所以我有代码以编程方式打开pdf。代码可以很好地打开adobe reader,但是我得到一个弹出的对话框,说文件不存在。问题是,虽然我可以浏览到用于尝试在windows探索中打开pdf的确切路径,另外还有一个if语句用于文件是否存在。为什么adobe不打开pdf?
Adobe .exe在proc.StartInfo.FileName
上的路径是正确的。
我发现了这个链接:https://visibleprocrastinations.wordpress.com/2009/08/20/there-was-an-error-opening-this-document-file-cannot-be-found-acrobat-reader/但我不知道它是否仍然适用
PDF文件路径:
C:UsersPrinterSharePointPartners - DocMcGLabelsTR109897eLabels_TR109897.pdf
下面是我使用的代码:Process proc = new Process();
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
//Define Location of adobe reader/command line
proc.StartInfo.FileName = @"C:Program Files (x86)AdobeReader 11.0ReaderAcroRd32.exe";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Arguments = string.Format(@"{0}", file.FullName);
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
if (proc.HasExited == false)
proc.WaitForExit(10000);
proc.Close();
return true;
}
听起来shell正在以一种意想不到的方式解析文件名。尝试用引号括起文件名:
proc.StartInfo.Arguments = string.Format(""{0}"", file.FullName);