Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
System.Web.HttpUtility + URLEncoded String
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 1.1
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01016140
Message ID:
01016354
Views:
13
This message has been marked as a message which has helped to the initial question of the thread.
>Hi how can i use System.Web.HttpUtility class in a WinForm. I just want to use the HttpUtility.URLEncode() of the that i Can integrate it to System.UriBuilder class. My first Problem actually it to Build a URL for the consumption of HttpWebRequest class then i notice that the String I pass is not URLEncode. Any Solution in creating and URLEncoded String?

You cna just add the System.Web namespace and use the class.

Because of the way that .NET dynamically loads assemblies and compiles code this is not as inefficient as it sounds <g>...

In .NET 2.0 some of the HttpUtility functions have been moved into the System.Net namespace.

If you'd rather not include System.Web you can use this function:
/// <summary>
/// UrlEncodes a string without the requirement for System.Web
/// </summary>
/// <param name="String"></param>
/// <returns></returns>
public static string UrlEncode(string InputString) 
{
	StringReader sr = new StringReader( InputString);
	StringBuilder sb = new StringBuilder(  InputString.Length );

	while (true) 
	{
		int Value = sr.Read();
		if (Value == -1)
			break;
		char CharValue = (char) Value;

		if (CharValue >= 'a' && CharValue < 'z' || 
			CharValue >= 'A' && CharValue < 'Z' || 
			CharValue >= '0' && CharValue < '9')
			sb.Append(CharValue);
		else if (CharValue == ' ') 
			sb.Append("+");
		else
			sb.AppendFormat("%{0:X2}",Value);
	}

	return sb.ToString();
}
+++ Rick ---
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform