3

I am saving files (images, Excel doc, Word doc, exe files, bat files and so on). I need to execute the file from inside my program and the question is if there is a way to let Windows handle how to run/execute the file? Like when you double click on a file in Explorer?

Ondrej Tucny
  • 26,009
  • 6
  • 63
  • 87
Banshee
  • 15,434
  • 36
  • 111
  • 198
  • possible duplicate of [ShellExecute equivalent in .NET](http://stackoverflow.com/questions/258416/shellexecute-equivalent-in-net) – Ondrej Tucny Mar 26 '12 at 09:37

2 Answers2

13

Take a look at the Process.Start method:

System.Diagnostics.Process.Start(myFileName)

Note: this will work with any registered file-extension, for example

System.Diagnostics.Process.Start(@"c:\Image.bmp")

will open the image with the registered program.

Carsten
  • 49,407
  • 9
  • 85
  • 111
3

Start new process with the saved file path name as a parameter:

System.Diagnostics.Process.Start(pathToYourFile);
Karel Frajták
  • 4,409
  • 20
  • 33