This documentation is archived and is not being maintained.

HttpServerUtility.UrlPathEncode Method

URL-encodes the path portion of a URL string and returns the encoded string.

[Visual Basic]
Public Function UrlPathEncode( _
   ByVal s As String _
) As String
public string UrlPathEncode(
 string s
public: String* UrlPathEncode(
 String* s
public function UrlPathEncode(
   s : String
) : String;


The text to URL-encode.

Return Value

The URL encoded text.


URL encoding ensures that all browsers will correctly transmit text in URL strings. Characters such as ?, &,/, and spaces may be truncated or corrupted by some browsers so those characters must be encoded in <A> tags or in query strings where the strings may be re-sent by a browser in a request string.


The following example URL-encodes a string before sending it to a browser client. In this example, the string MyURL will be encoded as " = ASP.NET Examples".

[Visual Basic] 
Dim MyURL As String
MyURL = " = ASP.NET Examples"

Response.Write( "<A HREF = " & Server.UrlPathEncode(MyURL) & "> ASP.NET Examples <br>")

String MyURL;
MyURL = " = ASP.NET Examples";

Response.Write( "<A HREF = " + Server.UrlPathEncode(MyURL) +  "> ASP.NET Examples <br>" );

String* MyURL;
MyURL = S" = ASP.NET Examples";

Response->Write( String::Format( S"<A HREF = {0}> ASP.NET Examples <br>", Server->UrlPathEncode(MyURL) ) );

var myURL : String
myURL = " = ASP.NET Examples"

Response.Write( "<A HREF = " + Server.UrlPathEncode(myURL) + "> ASP.NET Examples <br>")


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpServerUtility Class | HttpServerUtility Members | System.Web Namespace