miercuri, 12 ianuarie 2011

How to open a .pdf or .txt file in C#

This is a simple question, with a very simple answer. I've been asking it myself and seeing other people ask it. A solution is to use the System.Diagnostics.Process.Start( ) method.
According to MSDN, using this method is very similar to typing the file's name in the Run dialog box of the Windows start menu.
For instance, if you have a .pdf file that you want to open, just use:
System.Diagnostics.Process.Start( "myfile.pdf" );
You can follow this link for more information: http://msdn.microsoft.com/en-us/library/53ezey2s.aspx.

For a text file, you can use the above method, or if you want to specifically open it with notepad you have to use:
System.Diagnostics.Process.Start( "notepad.exe", "myfile.txt" );

Niciun comentariu:

Trimiteți un comentariu