How to: Launch application AND open the "triggering" file

  • Thread starter Thread starter Bob Lidgard
  • Start date Start date
B

Bob Lidgard

Hi, I need some help. Hopefully this is trivial!

I have created a special file type for my application. I can easily
associate the app with the file type manually and I have even seen som code
to do this as well. (MSDN - 185453)

However, once the app is launched after double-clicking on the file,
how can I identify which file was selected, i.e. triggered the launch.

Pls point me to the right direction for search!


Thanks,
Bob
 
Hi, I need some help. Hopefully this is trivial!

I have created a special file type for my application. I can easily
associate the app with the file type manually and I have even seen som code
to do this as well. (MSDN - 185453)

However, once the app is launched after double-clicking on the file,
how can I identify which file was selected, i.e. triggered the launch.

Pls point me to the right direction for search!


Thanks,
Bob

Bob,

I believe the file path is passed in as a command line argument. So,
just check the command line - either by including it in your main
declaration or use System.Environment.CommandLine or
System.Environment.GetCommandLineArgs to retrieve the command line...

' main method
Public Sub Main(ByVal Args() As String)
....

End Sub


' System.Envrionment.CommandLine

Dim cmdLine As String = System.Envrionment.CommandLine


'System.Environment.GetCommandLineArgs()

Dim cmdLine() As String = System.Environment.GetCommandLineArgs()

HTH,
Tom Shelton
 
* "Bob Lidgard said:
Hi, I need some help. Hopefully this is trivial!

I have created a special file type for my application. I can easily
associate the app with the file type manually and I have even seen som code
to do this as well. (MSDN - 185453)

However, once the app is launched after double-clicking on the file,
how can I identify which file was selected, i.e. triggered the launch.

Pls point me to the right direction for search!

\\\
Public Sub Main(ByVal astrCmdLineArgs() As String)
Dim i As Integer
For i = 0 To astrCmdLineArgs.Length - 1
Console.WriteLine(astrCmdLineArgs(i))
Next i
End Sub
///

Set the project's startup object to "Sub Main".
 
Hi Bob,

If you've tried to get the file name from the command line args and it's
still not working, check that the command in the file association has %1 as
its arguments.

Regards,
Fergus
 
Back
Top