Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This ought to do the trick...</p> <pre><code>var processInfo = new ProcessStartInfo(fileName); processInfo.Verb = "openas"; Process.Start(processInfo); </code></pre> <p>Although, Oded makes a great point - not knowing exactly how/where you intend to use such functionality means this might not be the answer for your situation.</p> <p>Recent comments on this answer go to show I wasn't very detailed in the first place. A problem will arise if you try to <code>openas</code> a file that already has the <code>open</code> verb defined against that type of file. Similarly, if you try to <code>open</code> a file that doesn't have that verb defined there'll be trouble. The issue would be:</p> <blockquote> <p>Win32Exception: No application is associated with the specified file for this operation</p> </blockquote> <p>Off the top of my head I suggested to Thomas that in order to use this kind of code in a production application you would need to be thorough and perhaps check the registry, or otherwise find out whether or not a file can and should be opened with any given verb. It could be simpler than that when you consider <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.verbs%28VS.90%29.aspx" rel="nofollow"><code>ProcessStartInfo.Verbs</code></a>: this will, once the <code>fileName</code> is set, provide you with a collection of possible verbs associated with the file type. This should make it easier to determine what to do with which file.</p> <p>To wrap up, as I mentioned to Thomas, you will need to take care and add some complexity/intelligence to your application - this answer certainly isn't a catch-all solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload