January 13, 2006

Retrieving Query Parameters in a Smart Client

OK, so there is this little cool feature in Smart Clients that allows you to start a .NET executable from a web page. You can set it up so the program is always started from the web page, or just use it as a distribution method.

I'm interested in the "only start from a web page" option.

But, this is only useful if you can pass data to the smart client from the web page. Preferable thru the URL. And guess what -- You CAN! You just have to pile through a lot of help docs to find the documentation on it.

So here is what you do.

In you program, you will need some code that looks like this:



if (ApplicationDeployment.IsNetworkDeployed)
{
// retrieve the url. It will look something like this:
// http://localhost/myapp.Application?Param=Var
string url =
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
// do something with the url
}



Next step is to call your application through your url with a parameter attached. It will probably look like this:
http://localhost/MyApp/MyApp.Application?Param=Var

Everything after the ? is up to you. Also left up to you is parsing the url for the parameters and values.

No comments: