tags:

views:

673

answers:

3

I have a clickonce application that is available online or offline. The program takes an argument. When online I pass the argument on the url like so "url?argument" and it works well. Offline i start a process with the startmenu link to the application.

My question is, is it possible to pass an argument to my application via this link? I guess I could somehow work out the location of the application file but is there an alternative?

A: 

No, you can't pass arguments from the Start Menu shortcut. If you find a way, let me know because I've been trying to do it for a long time :).

Here's how I address the problem in my situation...

If the ActivationUri property is not null, the application was launched from a browser and passed arguments via the query string (just like you described).

If the ActivationUri is null, the application was launched from the start menu. In these cases, I get the arguments from a config file deployed with the application.

What type of information is being passed with your argument? That would be useful in order to determine how you should store your arguments (app.config, application settings, user settings, isolated storage, etc.)

Side Note
I thought I was on to something by making my application "single instance" and trying to handle the StartupNextInstance application event, but no luck. You can only get traditional command line parameters that way, not the ClickOnce query string parameters.

whatknott
I posted my workaround solution here: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/9304f425-756f-4acb-9cf8-5d83abac57a8/?ffpr=0
A: 

You can pass arguments to an offline ClickOnce application. I would just set up a shortcut that points to the ClickOnce shortcut and adds arguments at the end. Click here to check out the article on how to pass and process arguments for an offline ClickOnce app.

RobinDotNet
A: 

I was able to get this to work by referencing the app as "$userprofile\Desktop\Your Shortcut Name Here.appref-ms"

Then, to pass the parms, pass them as a single, no space entity like so: arg1,arg2,arg3

The whole thing looks like this on the command line: "$userprofile\Desktop\Your Shortcut Name Here.appref-ms" arg1,arg2,arg3

Then in your code, use AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0] to retrieve the args.

I just blogged about this yesterday: http://www.developingfor.net/net/processing-command-line-arguments-in-an-offline-clickonce-application.html

Joel Cochran
Thanks for the heads up; that can be useful. Your blog entry is a short extract of mine which people may find useful. My blog entry does show how to do a comma-delimited argument list, but I didn't want to assume that the user only has arguments without spaces, commas, quotes, etc. in them. if you try the comma-delimited list and any of those characters show up, it ignores the rest of the argument list. That's the primary reason I included the html encoding example. (In case you were wondering).
RobinDotNet
Yes, I found your blog post very helpful, just way more detail than I needed :-)Also, for anyone who finds this later: the "$userprofile" above is supposed to be %userprofile% - not sure what happened there
Joel Cochran