|
-
Jan 2nd, 2004, 11:34 AM
#1
Thread Starter
Addicted Member
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.
-
Jan 2nd, 2004, 07:20 PM
#2
Frenzied Member
You can use any objects in the .net framework. All you have to do is add a reference to the object.
-
Jan 3rd, 2004, 07:32 AM
#3
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.
-
Jan 3rd, 2004, 12:06 PM
#4
Hyperactive Member
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();
}
}
}
-
Jan 3rd, 2004, 04:46 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|