pdf - Process.Start PDF 在文件夹中
问题描述
我无法让 Process.Start 简单地使用默认 PDF 查看器启动 PDF。
我尝试了许多 shell 执行、工作文件夹等的组合。不断给我“系统找不到指定的文件”或“目录名无效”
private void button1_Click(object sender, EventArgs e)
{
string filename = @"Milking and cooling software set 2018-39.pdf";
MessageBox.Show(currentpath + @"\Astronaut A5 v1.5(b7)\documentation\" + filename);
fullpath = currentpath + @"\Astronaut A5 v1.5(b7)\documentation";
fullfile = fullpath + filename;
ProcessStartInfo process = new ProcessStartInfo();
process.WorkingDirectory = fullpath;
process.UseShellExecute = false;
process.FileName = fullfile;
process.RedirectStandardOutput = true;
process.Verb = "run as";
Process.Start(process);
}
为什么这么难,我已经尝试了几个小时来简单地启动 Acrobat Reader 来打开 PDF 文件。我可以在它的位置双击它没问题,但 C# 无法打开它,要么我收到 .NET 错误,要么 Adobe 打开并说它找不到文件。尝试了这么多“\””、完整路径、硬编码路径等的组合......令人难以置信,在这个时代,这很难编码。
解决方案
您已告诉系统不要使用 ShellExecute。这意味着您提供的路径应该是一个实际的可执行程序。如果您想使用默认阅读器打开 PDF,请使用 ShellExecute。
process.UseShellExecute = true;
同样使用“run as”作为动词在这里没有任何意义,除非为 PDF 定义了这样一个动词,我很确定没有。那应该被删除。
推荐阅读
- php - 使用php阻止url指定的文件夹或路径
- ffmpeg - 使用 pkg-config 未找到编译 FFMPEG x265
- spring - 引起:java.lang.ClassNotFoundException: org.springframework.messaging.converter.MessageConverter 在微服务
- swift - 为什么没有迅速收到委托事件?
- mysql - 十月 CMS - 第 1 行的“内容”列的数据太长
- xml - ID / IDREF 的 Docbook / XML 限制
- javascript - 查询结果在JQuery函数中的错误响应
- jquery - 修复相对于父级的内容
- r - 基于R中的系数数据框的矩阵的加权元素
- python - 算术运算的Python问题