Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
System.Web.HttpUtility + URLEncoded String
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 1.1
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01016140
Message ID:
01016354
Vues:
14
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?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform