没有应用程序与该操作的指定文件关联(VB.NET) [英] No application is associated with the specified file for this operation (VB.NET)

查看:125
本文介绍了没有应用程序与该操作的指定文件关联(VB.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Win Forms应用程序,该应用程序使用iTextSharp生成pdf,并将其保存到本地目录,然后该应用程序打开文件.如果有一位客户(所有XP盒和Adobe Reader 11),则会引发以下错误

We have a Win Forms application that produces a pdf with iTextSharp, saves it to a local directory and the application then opens the file. With one customer (all XP boxes and Adobe Reader 11) it throws the following error

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可以导航到本地目录并打开文件而没有任何问题外,这暗示Adobe Reader与pdf扩展名没有正确关联.

Which would suggest Adobe Reader is not associated correctly with the pdf extension apart from the fact they can navigate to the local directory and open the file without any problem whatsoever.

有人遇到过这种奇怪吗?

Anyone come across this oddity before?

编辑ZippyV-典型子示例

Edit re ZippyV - example of a typical sub

 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

推荐答案

您正在阅读错误消息.我将重点放在了相关部分:

You're reading the error message wrong. I've added emphasis to the relevant part:

没有应用程序与指定的文件相关联用于此操作

这意味着没有与动词"Open"相关的应用程序.更改代码以仅使用空字符串(或不设置)Verb:

This means that there is no application associated with the verb "Open". Change your code to simply use an empty string (or just don't set) the Verb:

P.StartInfo.FileName = vOutput
P.StartInfo.Verb = ""
P.Start()

这将使用.pdf格式的默认操作,这将与用户双击Windows资源管理器中的文件所获得的操作相匹配.

This uses whatever the default operation is for the .pdf format, which will match the operation the user would get if they double-clicked the file in Windows Explorer.

最近的Acrobat版本将默认操作设置为使用Adobe Reader XI打开",而不仅仅是打开",因为您可以查看是否右键单击.pdf文件.

Recent versions of Acrobat are setting the default action to "Open with Adobe Reader XI" instead of just "Open", as you can see if you right-click a .pdf file.

这似乎是导致与此操作无关的"错误的原因.

This is seemingly what's causing the "not associated for this operation" error.

这篇关于没有应用程序与该操作的指定文件关联(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆