Launch A Document Using Default Application





8
Date Submitted Fri. Feb. 17th, 2006 3:49 PM
Revision 1 of 1
Beginner RRSands
Tags CSharp | Document | Execute | Launch | Run
Comments 0 comments
This snip opens any kind of document (e.g. .PDF, .DOC, .C, .HTM, etc.) using the default application associated with it. This relies on starting a new process with the .UseShellExecute property set to true.

The main overloaded function OpenDoc(filename) will open any associated document using the default OPEN verb. If you are trying to edit a file, for example, a command file, then you need should call OpenDoc with the "EDIT" verb. Some associations also a "PRINT" verb.

Since the return result is a System.Diagnostics.Process object, you can also monitor or kill the process.

Example:
OpenDoc("C:\\SomeDocumentation.pdf");
OpenDoc("C:\\AWebPage.htm", "EDIT");
OpenDoc("C:\\Test.txt", "PRINT");
System.Diagnostics.Process doc = OpenDoc("C:\\WebPage.htm");

public System.Diagnostics.Process OpenDoc(String Filename, String Verb)
{
        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
        info.FileName = Filename;
        info.UseShellExecute = true;
        info.Verb = Verb;
        info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
        return System.Diagnostics.Process.Start(info);
}

public System.Diagnostics.Process OpenDoc(String Filename)
{
        return OpenDoc(Filename, "OPEN");
}
 

Rick Sands

www.pdatoolbox.org

Comments

There are currently no comments for this snippet.

Voting