Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > & in a QueryString

Reply
Thread Tools

& in a QueryString

 
 
DaveF
Guest
Posts: n/a
 
      11-10-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
John Toop
Guest
Posts: n/a
 
      11-10-2004
Hi Dave,
I think you should URLEncode the string before you build the hyperlink.
Basically "&" will create your ampersand ("&")

jt
"DaveF" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
> (E-Mail Removed)
>
>



 
Reply With Quote
 
 
 
 
Shiva
Guest
Posts: n/a
 
      11-10-2004
'&' in the URL should be urlencoded as %26

"DaveF" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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
(E-Mail Removed)



 
Reply With Quote
 
chanmmn
Guest
Posts: n/a
 
      11-10-2004
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>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
> (E-Mail Removed)
>
>

 
Reply With Quote
 
Matt Berther
Guest
Posts: n/a
 
      11-11-2004
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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
>> (E-Mail Removed)



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get value of QueryString inside QueryString Mehdi ASP .Net 6 04-06-2006 03:41 PM
Passing QueryString URL as a paremeter in QueryString Adeel Ahmad ASP General 1 03-07-2006 02:05 PM
querystring in masterpages - please help suzy ASP .Net 3 04-16-2004 12:26 PM
Re: Pack QueryString Natty Gur ASP .Net 0 06-29-2003 02:48 PM
Pack QueryString Axel Dahmen ASP .Net 2 06-29-2003 01:46 PM



Advertisments