Froodle
Froodle

Reputation: 349

Open a file not using default program

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

Answers (3)

metalbea
metalbea

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.

right click menu on icon

windows explorer with chrome.exe highlighted

Upvotes: 0

D Stanley
D Stanley

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

  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.

Upvotes: 5

Magnum
Magnum

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

Related Questions