HttpUtility.UrlPathEncode Method (String, Boolean, Boolean, TextWriter)
Encodes the specified path part of a URL for HTTP transmission and appends it to the specified output stream.
Namespace: Microsoft.SharePoint.Client.Utilities
Assembly: Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)
Syntax
'Declaration
Public Shared Sub UrlPathEncode ( _
urlToEncode As String, _
allowHashParameter As Boolean, _
encodeUnicodeCharacters As Boolean, _
output As TextWriter _
)
'Usage
Dim urlToEncode As String
Dim allowHashParameter As Boolean
Dim encodeUnicodeCharacters As Boolean
Dim output As TextWriterHttpUtility.UrlPathEncode(urlToEncode, _
allowHashParameter, encodeUnicodeCharacters, _
output)
public static void UrlPathEncode(
string urlToEncode,
bool allowHashParameter,
bool encodeUnicodeCharacters,
TextWriter output
)
Parameters
urlToEncode
Type: System.StringA string that contains the path.
allowHashParameter
Type: System.Booleantrue to specify that the decode operation can include a hash parameter; otherwise, false.
encodeUnicodeCharacters
Type: System.Booleantrue to encode Unicode characters; otherwise, false.
output
Type: System.IO.TextWriterA TextWriter object that represents the output stream to which to add the encoded path. The encoded URL; empty if urlToEncode is empty, and null if urlToEncode is null.
Remarks
This method is a wrapper on an internal method to return an encoded URL as a string.
This method encodes characters that cannot be used in a URL with the following characters: control characters (0-31); ' '; '"'; '%'; '<' '>''\''; '&'; and characters greater than 0x7F up to the first '?' character.
If allowHashParameter is true, it stops at the first '#' character. Only use this method when you are constructing the URL. Do not use this method on a full URL, such as a URL entered by user. You still need to call HtmlUrlAttributeEncode. The '#' character is the marker for a bookmark in a URL, so it cannot be encoded. However, the '#' character is also a valid character in the file name, so it should be encoded; otherwise, the browser will mistake it for a bookmark. It is impossible to determine if the '#' is intended as a bookmark or utilized in a file name, so allowHashParameter is introduced to let the caller specify whether to encode the '#' or not.separately if you want to use the URL attribute value for an href or src attribute. Call the HtmlEncode method if you want to use the URL in other types of attributes or between HTML tags.
The '#' character is the marker for a bookmark in a URL, so it cannot be encoded. However, the '#' character is also a valid character in the file name, so it should be encoded; otherwise, the browser will mistake it for a bookmark. It is impossible to determine if the '#' is intended as a bookmark or utilized in a file name, so allowHashParameter is introduced to let the caller specify whether to encode the '#' or not.