gchq
gchq

Reputation: 1771

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

Upvotes: 13

Views: 68893

Answers (2)

the.net-learner
the.net-learner

Reputation: 53

This error actually happens when there is a difference between the default behaviour of opening the file and the relative behaviour of opening the file. For example, if you have selected the default application to open .pdf files as Internet Explorer, and you are trying to open the same file using Process.Start() method. You will receive an exception because as per the default operations it should open that file in Internet Explorer and your application is trying to open it using Adobe reader.

To rectify this set the default application for the .pdf file as Adobe Reader and you won't receive this error any more.

Upvotes: 0

Ken White
Ken White

Reputation: 125718

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.

Upvotes: 17

Related Questions