Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No application is associated with the specified file for this operation (VB.NET)

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()

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?

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
like image 258
gchq Avatar asked Jan 09 '14 22:01

gchq


1 Answers

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

No application is associated with the specified file for this operation

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()

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.

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.

Acrobat context menu as seen in Windows Explorer

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

like image 177
Ken White Avatar answered Nov 06 '22 02:11

Ken White