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,707
  • 6
  • 66
  • 88
Banshee
  • 15,436
  • 37
  • 114
  • 205
  • 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.

Random Dev
  • 50,967
  • 9
  • 90
  • 116
3

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

System.Diagnostics.Process.Start(pathToYourFile);
Karel Frajták
  • 4,473
  • 22
  • 34