KyleMit KyleMit - 4 years ago 117
Vb.net Question

How do I identify the file that launched my application

I'm trying to associate an application with a particular file type and then use that file when the application starts up. It's pretty trivial to Create File Associations For a ClickOnce Application:

Publish Options > File Associations

This currently works, so if I have an file with the extension ".tester," my Click Once Deployed application will fire up.

The problem I'm having trouble with is identifying which file launched the application.

According to the question What Event is Triggered When Opening a Custom File?, the "file should be available from the command line args", and this Scott Hanselman Article confirms.

However, when I add the following code, I don't get anything besides the path to the executable when firing the application.

Dim args = Environment.GetCommandLineArgs()
MsgBox(Join(args, ", "))


Command Line Args

I have confirmed that I'm fetching all the command line arguments. When I launch the file from the actual command line with some bogus arguments:

C:\FileHandler.exe -foo bar


The application will display the following:

args 2

How do I identify the file that initiated the application?

Answer Source

ClickOnce doesn't pass through standard command line args, but through the ActivationArguments instead.

Your file info should be available via AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download