Opening a file using its associated program

  • Thread starter Thread starter Gos
  • Start date Start date
G

Gos

Hi,

I have a program that needs to open a list of attachments
displayed on a ListView. I have used Process.Start method to open the
files using their associated program. This works correctly if the file
extention is associated with a process(program/application) already,
but throws an exception when there is no associated process. I would
like to display an "Open With.." dialog box where the user can choose
a program to open the file.

Can anyone please help me with this?

Thank you very much
Eric
 
(e-mail address removed) (Gos) scripsit:
I have a program that needs to open a list of attachments
displayed on a ListView. I have used Process.Start method to open the
files using their associated program. This works correctly if the file
extention is associated with a process(program/application) already,
but throws an exception when there is no associated process. I would
like to display an "Open With.." dialog box where the user can choose
a program to open the file.

You can catch the exception and call the function below:

PInvoke, seems to be undocumented:

\\\
Private Declare Function OpenWithDialog Lib "shell32.dll" _
Alias "OpenAs_RunDLL" ( _
ByVal hWndOwner As IntPtr, _
ByVal dwUnknown1 As Int32, _
ByVal strFileName As String, _
ByVal dwUnknown2 As Int32 _
) As Int32

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click
OpenWithDialog(Me.Handle, 0, "C:\AUTOEXEC.BAT", 0)
End Sub
///
 
Hi,

I have a program that needs to open a list of attachments
displayed on a ListView. I have used Process.Start method to open the
files using their associated program. This works correctly if the file
extention is associated with a process(program/application) already,
but throws an exception when there is no associated process. I would
like to display an "Open With.." dialog box where the user can choose
a program to open the file.

Can anyone please help me with this?

Thank you very much
Eric

Eric,

Set the process class's StartInfo.ErrorDialog property to true... This
will cause the Open With... dialog to appear if the process can't be
started.

Tom Shelton
 
Back
Top