C#中调用对应的应用程打开文件序的代码

80酷酷网    80kuku.com

  '浏览选择文件

OpenFileDialog   dlg   =   new   OpenFileDialog();  
   dlg.DefaultExt   =   "xls";  
   dlg.Filter   =   "Text   Files(*.xls)|*.xls||";  
   if   (dlg.ShowDialog()   ==   DialogResult.OK)  
   {  
    string   filePath   =   dlg.FileName;
    txtSourceFileName.Text=filePath;
   }

'调用外部应用程序打开选择的文件

string OpenFileName;
   OpenFileName=txtSourceFileName.Text;
   ProcessStartInfo pInfo = new ProcessStartInfo();
   pInfo.UseShellExecute = true;
    if (File.Exists(OpenFileName))
    {
     pInfo.FileName = OpenFileName;
     //启动进程
     Process p = Process.Start(pInfo);
    }
    


分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: