HttpUtility.UrlPathEncode Method (String, Boolean)

Encodes the specified path part of a URL for HTTP transmission.

Namespace:  Microsoft.SharePoint.Client.Utilities
Assembly:  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
Public Shared Function UrlPathEncode ( _
    urlToEncode As String, _
    allowHashParameter As Boolean _
) As String
'Usage
Dim urlToEncode As String
Dim allowHashParameter As Boolean
Dim returnValue As String

returnValue = HttpUtility.UrlPathEncode(urlToEncode, _
    allowHashParameter)
public static string UrlPathEncode(
    string urlToEncode,
    bool allowHashParameter
)

Parameters

  • urlToEncode
    Type: System.String

    A string that contains the path.

  • allowHashParameter
    Type: System.Boolean

    true to specify that the decode operation can include a hash parameter; otherwise, false.

Return Value

Type: System.String
The encoded URL; empty if urlToEncode is empty, and null if urlToEncode is null.

Remarks

This method is a wrapper on the UrlPathEncode(String, Boolean, Boolean) method with the encodeUnicodeCharacters parameter set to false.

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.

See Also

Reference

HttpUtility Class

HttpUtility Members

UrlPathEncode Overload

Microsoft.SharePoint.Client.Utilities Namespace