【发布时间】:2014-05-14 21:56:35
【问题描述】:
我正在编写一个 C# Windows 程序。在表格上,我有一个网站和 PDF 列表。当他们单击 PDF 时,代码会下载该文件,然后尝试打开它。在我的 Windows 8 机器上,PDF 可以正常打开。在 Windows 7 和 XP 机器上,它们没有打开,也没有视觉线索显示出问题所在。 (在这两台机器上,您都可以在文件资源管理器中单击 PDF,然后 PDF 将打开。)
我从查看Opening a pdf in .NET 开始,然后添加了它。这是我正在使用的...
if (File.Exists(localFileName))
{
//MessageBox.Show("calling file " + localFileName, "FYI...");
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "call /c " + localFileName;
process.StartInfo = startInfo;
try
{
//MessageBox.Show("calling file " + localFileName, "FYI...");
if (!process.Start())
{
MessageBox.Show("Could not invoke the PDF Viewer. Try opening the file at " + localFileName,
"Problem Opening File...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
}
catch (Exception exc)
{
MessageBox.Show("Couldn't start process (call " + localFileName + "), Message=" + exc.Message,
"Problem Encounter...", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//MessageBox.Show("Should be done", "FYI...");
}
我正在尝试检测进程是否启动。如果我无法让它们执行,如果我可以显示一条消息告诉用户在哪里查看以打开下载的文件,这将有所帮助。有什么想法吗?
【问题讨论】: