码迷,mamicode.com
首页 > Windows程序 > 详细

C#之 使用Process打开文件

时间:2018-07-17 19:27:56      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:tar   alc   message   box   启动   ica   存在   style   cat   

提供对本地和远程进程的访问权限并使你能够启动和停止本地系统进程。

Process可以打开文件,也可以打开exe的运行程序

现在先来说一下如何打开word文档:

 string fileNewPat = Application.StartupPath;
            string fileName = fileNewPat+@"\doc\程沐喆.doc";
            if (File.Exists(fileName))
            {
                Process process1 = new Process();
                process1.StartInfo.FileName = fileName;
                process1.StartInfo.Arguments = "";
                process1.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                process1.Start();
            }
            else
            {
                MessageBox.Show("文件不存在");
            }

打开Config文件:

 string stConfigFileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            stConfigFileName = Path.Combine(stConfigFileName, "UserConfigSettings");
            stConfigFileName += @".config";

打开Windows自带的计算器程序:


   Process process1 = new Process();
            process1.StartInfo.FileName = "calc.exe";
            process1.StartInfo.Arguments = "";
            process1.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
            process1.Start();

C#之 使用Process打开文件

标签:tar   alc   message   box   启动   ica   存在   style   cat   

原文地址:http://blog.51cto.com/13758648/2146022

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!