Results 1 to 5 of 5

Thread: UrlEncode / UrlDecode methods? [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141

    UrlEncode / UrlDecode methods? [RESOLVED]

    I need some UrlEncode and UrlDecode methods to use in a C# class. I'm not working under ASP.NET so I don't have the Server object.

    I'v been trying to create an instance of the HttpServerUtility object from the System.Web namespace, but it won't tell me what arguments its constructor needs and doesn't like it if I don't provide any.

    I don't mind writing a couple of functions to do the job myself, but I'm not entirely sure what characters should be encoded and which don't need to be.
    Last edited by mralston; Jan 3rd, 2004 at 04:48 PM.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You can use any objects in the .net framework. All you have to do is add a reference to the object.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    HttpSeverUtility doesn't have any constructors in its public interface...

    The formal specification of URLs is at www.w3.org.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    HttpServerUtility is exposed through HttpContext.Server, so it requires a context to use it that way. HttpUtility will work for ya, here's a console app sample(make sure to add a reference to System.Web.dll):
    PHP Code:
    using System;
    using System.Web;

    namespace 
    HttpUtilityTest
    {
        public class 
    MainApp
        
    {
            public static 
    void Main(string[] args)
            {
                
    string url "http://www.microsoft.com/some page here.aspx";
                
    string urlEncoded HttpUtility.UrlEncode(url);
                
    Console.WriteLine(urlEncoded);
                
    Console.ReadLine();            
            }
        }


  5. #5

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    Perfect, pbv. Works a treat!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width