473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Launch another application from within C# Winforms application

Hi
I am trying to use ShellExecute to launch an application to display a
certain file.

The variation on the theme is that I need to be able to specify the
application to launch and not simply pass the file name (which will
then result in the application associated with the file extension to
launch). I want to prevent the application registered in the system as
being associated with the file extension from opeing the file.

For instance, if MSPaint is associated with "*.bmp" file on my system
but I want to programatically open a file (also having a "*.bmp"
extension) with, say, Photoshop, how can I achieve this?

So far, I am using:

System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName=fileToLaunch;
p.StartInfo.UseShellExecute=false;
p.Start();
p.WaitForExit();
p.Dispose();

But this does not permit me to nominate the application I wish to use
to display the file.

Hope someone can assist.

Thanks

Grant
Nov 16 '05 #1
5 32705
Hi,

If you know the application exe name (and in some cases the path) you need
to launch, then it's usually only a case of passing the document to be opened
as an argument to ProcessInfo.
For eg:
ProcessStartInfo procInfo=new ProcessStartInfo("notepad", "c:\\a.txt");

Is this what you are looking for?

HTH,
Rakesh Rajan

"GrantS" wrote:
Hi
I am trying to use ShellExecute to launch an application to display a
certain file.

The variation on the theme is that I need to be able to specify the
application to launch and not simply pass the file name (which will
then result in the application associated with the file extension to
launch). I want to prevent the application registered in the system as
being associated with the file extension from opeing the file.

For instance, if MSPaint is associated with "*.bmp" file on my system
but I want to programatically open a file (also having a "*.bmp"
extension) with, say, Photoshop, how can I achieve this?

So far, I am using:

System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName=fileToLaunch;
p.StartInfo.UseShellExecute=false;
p.Start();
p.WaitForExit();
p.Dispose();

But this does not permit me to nominate the application I wish to use
to display the file.

Hope someone can assist.

Thanks

Grant

Nov 16 '05 #2
Excellent Rakesh

Thanks for your pointer, I will play with this.

Grant

su*************@hotmail.com (GrantS) wrote in message news:<69**************************@posting.google. com>...
Hi
I am trying to use ShellExecute to launch an application to display a
certain file.

The variation on the theme is that I need to be able to specify the
application to launch and not simply pass the file name (which will
then result in the application associated with the file extension to
launch). I want to prevent the application registered in the system as
being associated with the file extension from opeing the file.

For instance, if MSPaint is associated with "*.bmp" file on my system
but I want to programatically open a file (also having a "*.bmp"
extension) with, say, Photoshop, how can I achieve this?

So far, I am using:

System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName=fileToLaunch;
p.StartInfo.UseShellExecute=false;
p.Start();
p.WaitForExit();
p.Dispose();

But this does not permit me to nominate the application I wish to use
to display the file.

Hope someone can assist.

Thanks

Grant

Nov 16 '05 #3
> If you know the application exe name (and in some cases the path) you need
to launch, then it's usually only a case of passing the document to be opened as an argument to ProcessInfo.
For eg:
ProcessStartInfo procInfo=new ProcessStartInfo("notepad", "c:\\a.txt");


I want to let users view an XML log file with notepad, so I tried something
almost identical to your example:

System.Diagnostics.ProcessStartInfo notepadLog = new
System.Diagnostics.ProcessStartInfo("notepad.exe", "c:\\myLogFile.xml")

But nothing happens - am I missing something? .. do I need something like:

Application.Run(notpadLog) ?
Nov 16 '05 #4
Try this:

System.Diagnostics.Process.Start("notepad.exe", "C:\\myLogFile.xml");

That should launch the application for you and return Process object for
you to work with. Then again you can also pass your ProcessStartInfo
object to the Start method (it has a few overloads). Hope that helps.

Have A Better One!

John M Deal, MCP
Necessity Software

deko wrote:
If you know the application exe name (and in some cases the path) you need
to launch, then it's usually only a case of passing the document to be


opened
as an argument to ProcessInfo.
For eg:
ProcessStartInfo procInfo=new ProcessStartInfo("notepad", "c:\\a.txt");

I want to let users view an XML log file with notepad, so I tried something
almost identical to your example:

System.Diagnostics.ProcessStartInfo notepadLog = new
System.Diagnostics.ProcessStartInfo("notepad.exe", "c:\\myLogFile.xml")

But nothing happens - am I missing something? .. do I need something like:

Application.Run(notpadLog) ?

Nov 16 '05 #5
> System.Diagnostics.Process.Start("notepad.exe", "C:\\myLogFile.xml");

That should launch the application for you and return Process object for
you to work with. Then again you can also pass your ProcessStartInfo
object to the Start method (it has a few overloads). Hope that helps.


That works great! Thanks!

I also tried:

System.Diagnostics.ProcessStartInfo notepadLog = new
System.Diagnostics.ProcessStartInfo("notepad.exe", "c:\\myLogFile.xml");

System.Diagnostics.Process.Start(notepadLog);

That works, too - but requires more typing...
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mahesh Kumar.R | last post by:
I'm into designing an application in winforms but in near future my client may request the same thing in webforms. so (1) what are all the design guidelines and ways are there to migrate easily in...
1
by: Chris | last post by:
Hi Everyone, I have a backup application I'm working on that saves backups with an extension of .ABF. I have figured out how to make the association change with PInvoke/shell32, but would...
2
by: panuvin | last post by:
Hello all, I'm developing a rather simple Winforms application written in C# using MS Visual Studio.NET. The application uses a MS Access database as the backend database. The application is...
8
by: Andrus | last post by:
I'm creating C# WinForms client-server database application. This application reads data from PostgreSQL server using npgsql Dataadapter and DataReader classes and stores data mostly in Datasets...
3
by: =?Utf-8?B?Y2hlbmRyaWNrcw==?= | last post by:
I have a C# winforms application that makes periodic web service calls in background thread to my web service server. These calls work fine almost all the time but on rare occassions the web...
6
by: Paulers | last post by:
Hello, I am trying to manipulate a console based application from another application for example I need to launch the console application, provide it input and take the output from the console...
4
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
Visual Studio 2005, C# WinForms application: Here’s the question: How can I increase the standard 1 MB stack size of the UI thread in a C# WinForms application? Here’s why I ask: I’ve...
4
by: Andrus | last post by:
For winforms application with multiple related forms it is reasonable to create Linq database context object in start of application. Context object is released only when application exits. So...
1
by: Susan Harris | last post by:
I have a Windows (NT) service developed in .NET 3.5 (VS2008). I want this service to log messages to a WinForms application that will display it's progress to the user. It has to run under Vista,...
2
by: Johnny Jörgensen | last post by:
OK, I have to do a Winforms application (C# or VB doesn't matter - that's not the important point here) that interacts with a database on a web server using an ASP.NET web service. I've done a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.