Click-Once Deployed WinForms Receiving QueryString

Share

Have you ever tried to pass parameters on the query string to one of your "click once" web deployed WinForms application? If you have, you’ll likely end up with an empty query string, even after following the directions on the following MSDN pages:

http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.activationuri(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.activationuri.aspx
http://msdn2.microsoft.com/en-us/library/ms172242(VS.80).aspx

I spent countless hours debugging and researching this issue, finding no answers anywhere and finding several people posting questions in forums about this issue… all with no resolution!

Here are the general directions from MSDN:

1. Mark your WinForms application as being able to receive query string parameters (right-click project/properties/publish/options, check "Allow URL parameters to be passed to application").
2. In your code, you access the query string as so:
(new Uri(AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[x])).Query

I tried a million times trying to get my parameters to pass through to my application. Here’s how I was testing it:

1. Deploy your WinForms application (right-click project/publish, fill in path info, click next, etc… until published).
2. Browser opens up to something like: http://localhost/myapp/publish.htm
3. Click on address and add "?test=whatever" so the full URL looks like: http://localhost/myapp/publish.htm?test=whatever and hit enter to reload publish.htm with those paramters.
4. Click the "run" button on the publish page.
5. App opens up, but the query string is blank: (new Uri(AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[x])).Query

As it turns out, my code was right all along. The trick is in the URL. Forget the publish.htm page. It can’t do it. What you need for the URL is this:

http://localhost/myapp/myapp.application?test=whatever.

That’s the trick to it. This bypasses the publish page altogether and launches the application immediately AND your query string WILL have the proper data in it!.

Share