我正在尝试使用 C# 的 Process.Start()
在 Adobe 阅读器中打开 PDF 文件.
当我提供一个没有空格的路径时,它工作正常,但包含空格的路径和 pdf 文件无法打开。
这是我的代码:
Button btn = (Button)sender;
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "AcroRd32";
string s = btn.Tag.ToString();
//btn.Tag Contains the full file path
info.Arguments = s;
Process.Start(info);
如果是C:\\Users\\Manish\\Documents\\ms_Essential_.NET_4.5.pdf
它工作正常,但如果它是 F:\\Tutorials\\C#\\Foundational\\Microsoft Visual C# 2012 Step By Step V413HAV.pdf
Adobe Reader 给出错误提示 there was an error in opening the document file can't be found
.
我已经在 SO 中通读了许多与此主题相关的问题,但它不起作用。因为我不知道如何申请 @
我的字符串中的前缀 s
.
有什么办法解决这个问题吗?
最佳答案
只是一个小技巧,在客户端设置了一个默认的 PDF 阅读器:只需使用文件名作为 FileName
如果进程。通常你不关心使用哪个程序,所以这个解决方案就可以了:
Process.Start(pdfFileName);
这也不需要特殊引用,因此它会立即解决您的问题。
关于c# - 使用 Process.Start 打开 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252106/