winform 呼叫程序開啟word pdf ppt
阿新 • • 發佈:2019-02-17
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; } }