How do I launch files in C#

后端 未结 3 1558
感动是毒
感动是毒 2020-11-30 03:06

-Edit- I feel like an idiot. I had a feeling something like the answer below would work but didnt see any google results similar to the answers below. So when i saw this com

3条回答
  •  粉色の甜心
    2020-11-30 03:46

    Assuming that you just want to launch files which already have some associated applications (eg: *.txt is associated with notepad), Use System.Diagnostics.Process.

    e.g. :

     using System.Diagnostics;
        Process p = new Process();
        ProcessStartInfo pi = new ProcessStartInfo();
        pi.UseShellExecute = true;
        pi.FileName = @"MY_FILE_WITH_FULL_PATH.jpg";
        p.StartInfo = pi;
    
        try
        {
            p.Start();
        }
        catch (Exception Ex)
        {
            //MessageBox.Show(Ex.Message);
        }
    

    Note: In my PC, the pic opens in Windows Picture & Fax Viewer since that is the default application for *.jpg files.

提交回复
热议问题