My blog has moved! Redirecting…

You should be automatically redirected. If not, visit http://www.digitalfugu.com/blog/ and update your bookmarks.

Thursday, March 06, 2008

Click-Once Applications and URL Parameters

We have a number of .Net 2.0 Windows applications that are to be converted to Click-Once deployed applications. The problem that we had was that these applications are launched with command line parameters, which are not available when running off the web using Click-Once deployment. So the solution was to grab the same parameters from the URL query string parameters. No problem just use the following code to grab and parse them. The real problem came later.

public NameValueCollection GetQueryStringParameters()
{
NameValueCollection nameValueTable = new NameValueCollection();

if (ApplicationDeployment.IsNetworkDeployed)
{
if (ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;

if (!string.IsNullOrEmpty(queryString))
{
nameValueTable = HttpUtility.ParseQueryString(queryString);
}
}
}

return (nameValueTable);
}
When I went to run this code on my local machine as Click-Once, I wasn't getting any thing in the ActivationUri. It was null all the time. As it turns out you have to modify your project properties to allow it like so:
  1. Right-click your project
  2. Select "Properties"
  3. Select the "Publish" tab
  4. Click the "Options" button
  5. Check "Allow URL parameters to be passed to application"
  6. Click "OK"
  7. Re-publish your application
Your application should now be able to get the ActivationUri.

7 comments:

Unknown said...

what namespace were you including to reference "HttpUtility?" I have included System.Web, however I am unable to compile my windows application and publish it using Click-Once.

Motionless Mario said...

ddtree,

When you say you included System.Web, do you mean adding a "using" statement to your code or adding a reference to it in your solution?

I added a reference to System.Web to my solution. In the solution explorer expand the references node of the tree and double check to see if you have System.Web under that node. If not, right click the "References" node, click "Add Reference", select "System.Web" under .NET and click "OK". That should get you going.

Additionally I have a "using System.Web;" statement so that I don;t have to type System.Web.HttpUtility to access the class.

Unknown said...

All I had to do was manually add a System.Web reference to my Project, not just the "using" statement within the code.

Thanks again for you reply and you help on the Click-Once URL Parameters

JEFF

Motionless Mario said...

Glad to be of service.

Unknown said...

Ok, i can get the URI on the client, but how i pass the parameters? I tried to change the href on publish.htm, but it didnt work out.

Unknown said...

Forget it, it doesnt work on FF, but on IE its working.
Thanks.

Motionless Mario said...

That is right. Firefox 2 doesn't support click-once out of the box. However, you can install the FFClickOnce Firefox Add-on (https://addons.mozilla.org/en-US/firefox/addon/1608) to add support for Click-Once.