我们有一个 Win Forms 应用程序,它使用 iTextSharp 生成 pdf,将其保存到本地目录,然后应用程序打开该文件。对于一名客户(所有 XP 机器和 Adobe Reader 11),它会抛出以下错误
No application is associated with the specified file for this operation
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
这表明 Adobe Reader 与 pdf 扩展名没有正确关联,除了它们可以导航到本地目录并打开文件而没有任何问题之外。
有人以前遇到过这种奇怪的情况吗?
编辑 ZippyV - 典型子示例
Public Sub PDF_Functions_LogCalls_RunReport(ByVal Customer As Boolean)
Try
Dim vOutput As String = LogCalls_Run(Customer)
If Left(vOutput, 5) = "Error" Then
TaskDialog.Show(MainForm, AppBoxError("File Error", vOutput, "Error"))
Exit Sub
End If
If System.IO.File.Exists(vOutput) Then
Dim P As New Process
P.StartInfo.FileName = vOutput
P.StartInfo.Verb = "Open"
P.Start()
End If
Catch ex As Exception
EmailError(ex)
Exit Sub
End Try
End Sub
您读错了错误消息。我对相关部分添加了强调:
没有应用程序与指定的文件关联对于此操作
这意味着不存在与动词“Open”相关联的应用程序。更改您的代码以仅使用空字符串(或只是不设置)Verb
:
P.StartInfo.FileName = vOutput
P.StartInfo.Verb = ""
P.Start()
这将使用 .pdf 格式的默认操作,这将与用户在 Windows 资源管理器中双击该文件时获得的操作相匹配。
最新版本的 Acrobat 将默认操作设置为“使用 Adobe Reader XI 打开”,而不仅仅是“打开”,如右键单击 .pdf 文件时可以看到的那样。
这似乎是导致“与此操作无关”错误的原因。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)