views:

87

answers:

2

hi all, how can i start any application from C#

i mean for example, if i have an openfiledialog and the user opened it and selected any file and opened it, i need this file to opened in its application whatever its extension and its default start application.

i have googled and found that Process.Start takes the file name and its application but i don't know what is the type of the file the user is going o open thanks in advance for any replies.

+4  A: 

You can call Process.Start with any filename and the file will open in its default program.

SLaks
Yes, u can try System.Diagnostics.Process.Start("\test.exe","").Ref : http://myewt.blogspot.com/2007/07/how-to-run-exe-from-running-program.html
Ram
@Ram: The point is that you can call `Process.Start(@"C:\Path\MyFile.doc") and it will open in Word.
SLaks
+5  A: 

Process.Start has several overloads; you want the one that takes only a string. From MSDN:

It can be of any file type for which the extension has been associated with an application installed on the system. For example the file name can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated .doc files with a word processing tool, such as Microsoft Word.

Example:

Process.Start(myOpenFileDialog.FileName);
Thomas