使用Process.Start打开pdf文件

Man*_*ngh 1 c# pdf process.start

我正在尝试使用C#在Adobe Reader中打开PDF文件Process.Start().

当我提供没有空格的路径时,它工作正常,但包含空格的路径和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); 
Run Code Online (Sandbox Code Playgroud)

如果它C:\\Users\\Manish\\Documents\\ms_Essential_.NET_4.5.pdf工作正常但如果是F:\\Tutorials\\C#\\Foundational\\Microsoft Visual C# 2012 Step By Step V413HAV.pdfAdobe Reader则会出错there was an error in opening the document file can't be found.

我已经在SO中阅读了与此主题相关的许多问题,但它不起作用.因为我无法弄清楚如何@在我的字符串中应用前缀s.

任何想法如何解决这一问题?

Pat*_*man 7

只是一个小技巧,在客户端上设置了一个默认的PDF阅读器:只需使用文件名就像FileName进程一样.通常你不关心使用哪个程序,所以这个解决方案正常工作:

Process.Start(pdfFileName);
Run Code Online (Sandbox Code Playgroud)

这也不需要特别引用,因此它可以立即解决您的问题.

  • 在发布问题之前我已经尝试过,但我需要它是特定于程序的,以供将来参考,但是,无论如何,感谢您的帮助 (2认同)

Som*_*ken 5

尝试将参数包装在引号周围:

info.Arguments = "\"" + s + "\"";
Run Code Online (Sandbox Code Playgroud)