Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > URLEncode

Reply
Thread Tools

URLEncode

 
 
Russ
Guest
Posts: n/a
 
      08-04-2003
Response.Redirect(@".\folder\" + filename);

How could I urlencode this statement so that if the filename contains a
special character (in my case a #) the redirect will still function?


 
Reply With Quote
 
 
 
 
Steve C. Orr, MCSD
Guest
Posts: n/a
 
      08-04-2003
Use the Server.URLEncode method.
Here's more info:
http://www.4guysfromrolla.com/webtech/042601-1.shtml

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net



"Russ" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Response.Redirect(@".\folder\" + filename);
>
> How could I urlencode this statement so that if the filename contains a
> special character (in my case a #) the redirect will still function?
>
>



 
Reply With Quote
 
 
 
 
Russ
Guest
Posts: n/a
 
      08-04-2003
Here is what I came up with

Response.Redirect(@".\folder\" + Server.UrlEncode(filename));

Now if my filename is 5373453 Store #2345.pdf

This is what I get in the address bar:
http://localhost/Path/folder/5373453+Store+%232345.pdf
This is not working though.

Anyone know why it is not working?



"Russ" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Response.Redirect(@".\folder\" + filename);
>
> How could I urlencode this statement so that if the filename contains a
> special character (in my case a #) the redirect will still function?
>
>



 
Reply With Quote
 
mikeb
Guest
Posts: n/a
 
      08-04-2003

"Russ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here is what I came up with
>
> Response.Redirect(@".\folder\" + Server.UrlEncode(filename));
>
> Now if my filename is 5373453 Store #2345.pdf
>
> This is what I get in the address bar:
> http://localhost/Path/folder/5373453+Store+%232345.pdf
> This is not working though.
>
> Anyone know why it is not working?
>


Possibly. Server.UrlEncode() encodes things using a pseudo-standard based
on how browsers implemented the <isindex> tags a long time ago, and how
query parameters are usually encoded even today. Spaces get encoded to '+'.
This type of encoding is only suitable for the query parameters portion of a
URL.

RFC 1738 specifies that spaces should be encoded using %20. As far as I
know, there's no easily accessible method to RFC 1738 encode URLs in the
framework:

- if using JScript.NET you can call the encodeURI() or the
encodeURIComponent() global function

- there are protected methods of the Uri class that do this, if you
want to create a class that inherits from it to do the work you need

- or you can use his hack:

string encodedUrl = (new UriBuilder( "http", "localhost", 80,
originalFilename)).Path;


However, I don't think the UriBuilder constructor will encode the '#'
character for you, as that is a valid character in a URL - though it has
special meaning (it's the fragment separator). If your filename contains a
'#' character, it will need to be escaped (into %23) to work correctly, and
you might need to do that on your own.

You should look at RFC 1738 and the documentation for Javascript's
encodeURIComponent().

>
>
> "Russ" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Response.Redirect(@".\folder\" + filename);
> >
> > How could I urlencode this statement so that if the filename contains a
> > special character (in my case a #) the redirect will still function?
> >
> >

>
>


--
MikeB


 
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
asp server.UrlEncode VS asp.net Server.UrlEncode Vs Php urlencode Dario Sala ASP .Net 1 11-15-2004 11:27 PM
Difference between System.Web.HttpUtility.UrlEncode and Server.UrlEncode? Andreas Klemt ASP .Net 4 01-22-2004 01:35 AM
UrlEncode-ing System.Web.HttpCookie values Chris ASP .Net 0 12-09-2003 08:53 PM
URLEncode Problem from ASP.NET vtreddy ASP .Net 5 10-25-2003 09:27 PM
Datagrid HYperlinnk column URLEncode vtreddy ASP .Net 0 10-24-2003 01:32 AM



Advertisments