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;
}
}