
UrlPathEncode | 399
ServerUtility
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Like the UrlDecode method, UrlEncode is overloaded. It returns a string when
called with the
s argument alone and does not return a value when called with
both the
s and output arguments. Instead, the encoded URL is sent to the writer
object.
UrlPathEncode
returnstring = Server.UrlPathEncode(s)
Returns a string containing a URL whose path portion is encoded using the URL
literal equivalents of symbols such as slash (/), colon (:), and dot (.). The method
also encodes any spaces in the remaining portion of the URL, since spaces in the
query string may be unexpectedly truncated by some browsers.
Parameters
returnstring
A String variable to receive the encoded string from the method.
s
A String variable containing the URL to be encoded by the method.
Example
The code example declares two string variables, sets the value of StrToEncode,
assigns the return value of the Server.UrlPathEncode call to
StrToReturn, and then
writes the value to the browser as part of a hyperlink:
Sub Page_Load( )
Dim StrToEncode As String
Dim StrToReturn As String
StrToEncode = "http://www.aspnetian.com/Chapter18/UrlPathEncode.aspx"
StrToReturn = Server.UrlPathEncode(StrToEncode)
Message.Text = "<a href=""UrlPathEncode.aspx?target=" & _
StrToReturn & """>" & StrToReturn & "</a><br/>" ...