Launch A Document Using Default Application
November 24, 2007
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”);
}
Entry Filed under: .Net. .
Trackback this post | Subscribe to the comments via RSS Feed