View file based on it's file type - extension

  • Thread starter Thread starter Ryan
  • Start date Start date
R

Ryan

I pass a filename to a method which needs to open that file up with the
aPPlication associated with that filename. If the file MyFile.txt then the
method should open it up in Notepad,. If MyFile.doc is passed then it should
be open up in MS Word.
I am using vs2005.
 
Use the Process class, passing the document name as the  
ProcessStartInfo.FileName used.  As long as you don't change the default  
value of ProcessStartInfo.UseShellExecute from "true", the Process class  
will use the Windows Explorer shell's file type associations to launch the  
appropriate program.

Pete

The quick and dirty method is to:

Process.Start("filename");
 
Back
Top