URLEncode

Discussion in 'ASP .Net' started by Russ, Aug 4, 2003.

  1. Russ

    Russ Guest

    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?
     
    Russ, Aug 4, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%...
    > 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?
    >
    >
     
    Steve C. Orr, MCSD, Aug 4, 2003
    #2
    1. Advertising

  3. Russ

    Russ Guest

    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 #2345.pdf
    This is not working though.

    Anyone know why it is not working?



    "Russ" <> wrote in message
    news:%...
    > 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?
    >
    >
     
    Russ, Aug 4, 2003
    #3
  4. Russ

    mikeb Guest

    "Russ" <> wrote in message
    news:...
    > 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 #2345.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" <> wrote in message
    > news:%...
    > > 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
     
    mikeb, Aug 4, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vtreddy

    Datagrid HYperlinnk column URLEncode

    vtreddy, Oct 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    404
    vtreddy
    Oct 24, 2003
  2. vtreddy

    URLEncode Problem from ASP.NET

    vtreddy, Oct 25, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    5,714
    vtreddy
    Oct 25, 2003
  3. Chris
    Replies:
    0
    Views:
    705
    Chris
    Dec 9, 2003
  4. Andreas Klemt
    Replies:
    4
    Views:
    10,362
    mikeb
    Jan 22, 2004
  5. Dario Sala
    Replies:
    1
    Views:
    3,862
    Karl Seguin
    Nov 15, 2004
Loading...

Share This Page