By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

& in a QueryString

P: n/a
I am looping threw the querySting with:
foreach (string name in Request.QueryString)

I have a problem with a '&' being in one of the values. How do I deal with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--
David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
da***@helixpoint.com
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Dave,
I think you should URLEncode the string before you build the hyperlink.
Basically "&" will create your ampersand ("&")

jt
"DaveF" <df*****@geodecisions.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
I am looping threw the querySting with:
foreach (string name in Request.QueryString)

I have a problem with a '&' being in one of the values. How do I deal with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--
David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
da***@helixpoint.com

Nov 18 '05 #2

P: n/a
'&' in the URL should be urlencoded as %26

"DaveF" <df*****@geodecisions.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
I am looping threw the querySting with:
foreach (string name in Request.QueryString)

I have a problem with a '&' being in one of the values. How do I deal with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--
David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
da***@helixpoint.com

Nov 18 '05 #3

P: n/a
No... you & is legal. Check for other:

Example:

Dim uriString As String = "http://www.contoso.com/search"
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Create a new NameValueCollection instance to hold the QueryString parameters and values.
Dim myQueryStringCollection As New NameValueCollection()
Console.Write(("Enter the word(s), separated by space characters, to search for in " + uriString + ": "))
' Read user input phrase to search in uriString.
Dim searchPhrase As String = Console.ReadLine()
' Append necessary parameter/value pairs to the name/value container.
' as QueryString = "?q=Microsoft&btnG=Google+Search".
If searchPhrase.Length > 1 Then
'Assign the user-defined search phrase.
myQueryStringCollection.Add("q", searchPhrase)
' If error, default to search 'Microsoft'.
Else
myQueryStringCollection.Add("q", "Microsoft")
End If
' Assign auxilliary parameters required for the search.
myQueryStringCollection.Add("btnG", "Google" + ChrW(43) + "Search")
Console.WriteLine(("Searching " + uriString + " ......."))
' Attach QueryString to the WebClient.
myWebClient.QueryString = myQueryStringCollection
' Download the search results Web page into 'searchresult.htm' for inspection.
myWebClient.DownloadFile(uriString, "searchresult.htm")
Console.WriteLine((ControlChars.Cr + "Download of " + uriString + " was successful. Please see 'searchresult.htm' for results."))
"DaveF" <df*****@geodecisions.com> wrote in message news:OX**************@TK2MSFTNGP10.phx.gbl...
I am looping threw the querySting with:
foreach (string name in Request.QueryString)

I have a problem with a '&' being in one of the values. How do I deal with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--


David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
da***@helixpoint.com

Nov 18 '05 #4

P: n/a
Hello chanmmn,

& is legal ... as an item delimiter.

If one of your items contains a &, it needs to be escaped (%26). You can
do this manually or with Server.UrlEncode(value). If you dont do this, then
the query string will be goofed up, because the delimiters are in the wrong
spot.

--
Matt Berther
http://www.mattberther.com
No... you & is legal. Check for other:

Example:

Dim uriString As String = "http://www.contoso.com/search"
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Create a new NameValueCollection instance to hold the QueryString
parameters and values.
Dim myQueryStringCollection As New NameValueCollection()
Console.Write(("Enter the word(s), separated by space characters, to
search for in " + uriString + ": "))
' Read user input phrase to search in uriString.
Dim searchPhrase As String = Console.ReadLine()
' Append necessary parameter/value pairs to the name/value container.
' as QueryString = "?q=Microsoft&btnG=Google+Search".
If searchPhrase.Length > 1 Then
'Assign the user-defined search phrase.
myQueryStringCollection.Add("q", searchPhrase)
' If error, default to search 'Microsoft'.
Else
myQueryStringCollection.Add("q", "Microsoft")
End If
' Assign auxilliary parameters required for the search.
myQueryStringCollection.Add("btnG", "Google" + ChrW(43) + "Search")
Console.WriteLine(("Searching " + uriString + " ......."))
' Attach QueryString to the WebClient.
myWebClient.QueryString = myQueryStringCollection
' Download the search results Web page into 'searchresult.htm' for
inspection.
myWebClient.DownloadFile(uriString, "searchresult.htm")
Console.WriteLine((ControlChars.Cr + "Download of " + uriString + "
was
successful. Please see 'searchresult.htm' for results."))
"DaveF" <df*****@geodecisions.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
I am looping threw the querySting with:
foreach (string name in Request.QueryString)
I have a problem with a '&' being in one of the values. How do I deal

with
this?

page.asp?theVal=2&theVal2=aa&e overdue
--
David Fetrow
Helixpoint LLC.
http://www.helixpoint.com
da***@helixpoint.com

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.