I want to make a string into a URL using C#, there must be something in the .NET framework that should help, right?.
Thanks. Haim.
I want to make a string into a URL using C#, there must be something in the .NET framework that should help, right?.
Thanks. Haim.
I believe you're looking for HttpServerUtility.UrlEncode.
System.Web.HttpUtility.UrlEncode(string url)
From the docs:
String TestString = "This is a <Test String>.";
String EncodedString = Server.HtmlEncode(TestString);
Update: This actually encodes Html not Urls. Use UrlEncode(TestString) as everyone who can read better than me said. Not deleting this on the off chance someone finds this thread while looking for html encoding.
Another way of doing this is using Uri.EscapeUriString(stringToEscape)
.
I found useful System.Web.HttpUtility.UrlPathEncode(string str);
It replaces spaces with %20 and not with +.