winform 调用进程打开word pdf ppt

 private void OpenWendang(string strname)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            
            string str = System.Windows.Forms.Application.StartupPath + "\\wendang\\" + strname;
            string strs = System.IO.Path.GetFullPath(str);
            string strhzm = System.IO.Path.GetExtension(str);
            if (strhzm.ToLower() == ".doc" || strhzm.ToLower() == ".docx")
            {
                startInfo.FileName = "WINWORD.EXE";//POWERPNT
                startInfo.Arguments = strs;
            }
            else if (strhzm.ToLower() == ".pptx" || strhzm.ToLower() == ".ppt")
            {
                startInfo.FileName = "POWERPNT.EXE";//POWERPNT
                startInfo.Arguments = strs;
            }
            else if (strhzm.ToLower() == ".pdf" )
            {
                //startInfo.FileName = "JisuPdf.exe";//POWERPNT
                //startInfo.FileName = @"C:\Program Files\极速PDF阅读器\JisuPdf.exe";
                startInfo.FileName = strs;
            }
            //startInfo.FileName = "JisuPdf.EXE";//POWERPNT
            
            try
            {
                Process.Start(startInfo);
            }
            catch
            {
                MessageBox.Show("您电脑没有安装office2007或者没有安装极速pdf软件,无法打开文件请安装再试谢谢!");
                return;

            }
        }

如果文件目录有空格会出现错误打不开
调整测试了下改成下面的
private void OpenWendang(string strname)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            
            string str = System.Windows.Forms.Application.StartupPath + "\\wendang\\" + strname;
            string strs = System.IO.Path.GetFullPath(str);
            string strhzm = System.IO.Path.GetExtension(str);
            //if (strhzm.ToLower() == ".doc" || strhzm.ToLower() == ".docx")
            //{
            //    startInfo.FileName = "WINWORD.EXE";//POWERPNT
            //    startInfo.Arguments = strs;
            //}
            //else if (strhzm.ToLower() == ".pptx" || strhzm.ToLower() == ".ppt")
            //{
            //    startInfo.FileName = "POWERPNT.EXE";//POWERPNT
            //    startInfo.Arguments = strs;
            //}
            //else if (strhzm.ToLower() == ".pdf" )
            //{
            //    //startInfo.FileName = "JisuPdf.exe";//POWERPNT
            //    //startInfo.FileName = @"C:\Program Files\极速PDF阅读器\JisuPdf.exe";
            //    startInfo.FileName = strs;
            //}
            startInfo.FileName = strs;
            //startInfo.FileName = "JisuPdf.EXE";//POWERPNT
            
            try
            {
                Process.Start(startInfo);
            }
            catch
            {
                MessageBox.Show("您电脑没有安装office2007或者没有安装极速pdf软件,无法打开文件请安装再试谢谢!");
                return;

            }
        }




发布了68 篇原创文章 · 获赞 6 · 访问量 11万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览