URLEncode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Russ

    #1

    URLEncode

    Response.Redire ct(@".\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

    #2
    Re: URLEncode

    Use the Server.URLEncod e method.
    Here's more info:


    --
    I hope this helps,
    Steve C. Orr, MCSD




    "Russ" <russ@acordiamn .com> wrote in message
    news:%23PeBfGsW DHA.2328@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Response.Redire ct(@".\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?
    >
    >[/color]


    Comment

    • Russ

      #3
      Re: URLEncode

      Here is what I came up with

      Response.Redire ct(@".\folder\" + Server.UrlEncod e(filename));

      Now if my filename is 5373453 Store #2345.pdf

      This is what I get in the address bar:

      This is not working though.

      Anyone know why it is not working?



      "Russ" <russ@acordiamn .com> wrote in message
      news:%23PeBfGsW DHA.2328@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > Response.Redire ct(@".\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?
      >
      >[/color]


      Comment

      • mikeb

        #4
        Re: URLEncode


        "Russ" <russ@acordiamn .com> wrote in message
        news:ewVZYpsWDH A.1888@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Here is what I came up with
        >
        > Response.Redire ct(@".\folder\" + Server.UrlEncod e(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?
        >[/color]

        Possibly. Server.UrlEncod e() 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
        encodeURICompon ent() 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,
        originalFilenam e)).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
        encodeURICompon ent().
        [color=blue]
        >
        >
        > "Russ" <russ@acordiamn .com> wrote in message
        > news:%23PeBfGsW DHA.2328@TK2MSF TNGP12.phx.gbl. ..[color=green]
        > > Response.Redire ct(@".\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?
        > >
        > >[/color]
        >
        >[/color]

        --
        MikeB


        Comment

        Working...