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
  • 27,626
  • 6
  • 70
  • 90
Banshee
  • 15,376
  • 38
  • 128
  • 219
  • 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
  • 51,810
  • 9
  • 92
  • 119
3

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

System.Diagnostics.Process.Start(pathToYourFile);
Karel Frajták
  • 4,389
  • 1
  • 23
  • 34