Click here to Skip to main content
15,894,262 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Again my newb nature with installers is probably showing, but I am finding that the msdn walkthroughs for file types on their installers is terribly lacking. I can't find anything in there that explains how to get the file you just clicked on as a value that your code can then recognize. I had hoped that the default value on the arguments property of a given verb/action would do what I need. The file type starts with &open as the only action (which is fine by me). That action/verb has an arguments parameter that is set to "%1". That didn't look all that useful to me, but I had hoped that it would somehow be what I need.

I have code at the initialization of my WPF application that gets the command arguments as follows:

var args = Environment.GetCommandLineArgs();
            String fileName = "";
            if (args != null && args.Length > 0)
                fileName = args[0];
			InitializeComponent();
            _application = new ApplicationViewModel(fileName);


When I pass a string into that viewmodel, it knows to open the file. If it fails it displays a prompt saying what file it failed to open. No surprise, the prompt is saying it couldn't open a blank or empty string.

Can anyone please help point me to what I need to put as the argument for my file type action to let my code know what the path of the file I just clicked on is?
Posted

1 solution

The default parameter value provided by the installer is right, but the code above was not the right code to get to the parameter.

For my WPF app, I had to go into the code behind for app.xaml. Override the OnStartUp and you have the parameter in an args property.

C#
public String LoadedFileName = "";
       protected override void OnStartup(StartupEventArgs e)
       {
           if (e.Args != null && e.Args.Length == 1)
           {
               String fileName = e.Args[0];
               if (!String.IsNullOrEmpty(fileName))
                   LoadedFileName = fileName;
           }
       }


Then in the code for main window you cast Application.Current as the appropriate class so you can look at the LoadedFileName
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900