Reputation: 349
How in c# can I make a file open with a specified program ie: not the default program for that file type
Upvotes: 4
Views: 6672
Reputation: 43
All the answers I found on the internet say that you can just use Process.Start("MyProgram.exe")
but I always get an exception that the file is not found so I got it working by specifying the full path to the .exe file in the installation folder
Process.Start(@"C:\Program Files\Google\Chrome\Application\chrome.exe")
you can find the installation folder by clicking on the right mouse button on a shortcut in the desktop and press Open file location
.
Upvotes: 0
Reputation: 152491
If you can build a command-line to run the program (including passing the input file as a command-line parameter) than build the command line ans use Process.Start
.
Of course this assumes
How 2. works depends on the program. It could be as simple as
Process.Start("MyProgram.exe","MyFile.dat")
But other programs may require a command-line switch or other information.
Upvotes: 5
Reputation: 1595
You can use the System.Diagnostics.Process(String, String)
method that you can find further documentation here
Sample:
// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
For future posts, I suggest you post code that you have already attempted/written to help us better help you.
Upvotes: 3