Win32Exception异常:即使已关联,也没有应用程序

问题描述 投票:1回答:2

我有C#程序,它在生成过程中将使用PrintTo谓词发送以将文件打印到指定的打印机。但是,当我尝试打印.pdf或html文件时,它说

Unhandled Exception: System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

我已经安装了PDF Complete,并且双击pdf文件可以正确打开它。 .html文件也会发生相同的事情(我将Mozilla Firefox作为默认浏览器)。

编辑:

我的代码:

ProcessStartInfo info = new ProcessStartInfo(args[0]);
info.Arguments = "\"" + args[1] + "\"";
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
info.Verb = "PrintTo";
Process.Start(info);

和命令行调用:>myapp.exe D:\Temp\test.pdf "PDF Complete"

例如>myapp.exe D:\Temp\test.txt "PDF Complete"有效

c# file pdf printing associations
2个回答
2
投票

对于仍然有兴趣的人。 PDF Complete和Firefox都不完全支持PrintTo动词


0
投票

我在打印.pdf的方法上有类似的错误。一切正常,直到我的计算机由于硬盘控制器上的阵列故障而崩溃。

重建计算机后,我回到完成此代码部分的位置。但是,它不起作用-我在上面的OP中列出了错误。

[经过一番检查并检查了该线程后,我发现Windows 10使用Edge处理.pdf文件。我安装了Adobe Reader和中提琴〜!不再有错误,Process.Start()打印文件。

© www.soinside.com 2019 - 2024. All rights reserved.