Page 1 of 1

C# HELP

Posted: 10 Sep 2007, 15:25
by LSG
I have a problem that I need to solve right away and I'm in desperate need for help. Can anyone tell me how to parse a query using a page.clientquerystring?

Posted: 10 Sep 2007, 15:49
by Hex_Rated
I don't know much about ASP.NET but I would assume you firstly split it into an array of strings using .Split('&') and then split each element further with .Split('=')

The second split should give you an array of length 2. The first element will be the parameter name and the second will be it's value. You can send the parameter name through a switch statement.

There's probably an easier way to do this...

Posted: 10 Sep 2007, 16:56
by Ron2K
There is indeed an easier way.

Let's look at a URL like this: http://www.pcformat.co.za/modules.php?n ... ic&t=26378

You would then call the following code to get the values in the query:

Request.QueryString["name"]
Request.QueryString["file"]
Request.QueryString["t"]

In the URL I provided earlier, they would return "Forums", "viewtopic" and "26378" respectively

Strings are returned; if you want other data types returned, you'll have to manually convert.

If you request something that isn't there (in the URL above, something like Request.QueryString["warble"]), null is returned.

Hope this helps.