我不能让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打开并说它找不到文件。尝试了许多“\”,完整路径,硬编码路径等etc...unbelievable的组合,这在当今时代是很难编码的。
发布于 2018-10-19 12:36:59
您已经告诉系统不要使用ShellExecute。这意味着你给出的路径应该是一个实际的可执行程序。PDF并非如此,如果你想用默认的阅读器打开它,请使用ShellExecute。
process.UseShellExecute = true;此外,使用“run as”作为动词在这里没有任何意义,除非为PDF定义了这样一个动词,但我非常确定没有这样的动词。
https://stackoverflow.com/questions/52885790
复制相似问题