Question

How in c# can I make a file open with a specified program ie: not the default program for that file type

Was it helpful?

Solution 2

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.

OTHER TIPS

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

  1. you know the path to the program's executable
  2. you know how to pass the filename as a command-line parameter.

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.

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.

right click menu on icon

windows explorer with chrome.exe highlighted

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top