Partilhar via


SP.Utilities.HttpUtility.urlPathEncode(str) Method

Applies to: SharePoint Foundation 2010

In this article
Return Value
Applies To
Remarks

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

var value = SP.Utilities.HttpUtility.urlPathEncode(str);

Parameters

str

Type: string

  • urlToEncode
    A string that contains the path.
  • allowHashParameter
    true to specify that the decode operation can include a hash parameter; otherwise, false.

Return Value

Type: string

Applies To

SP.Utilities.HttpUtility Class

Remarks

This method is a wrapper on SP.Utilities.HttpUtility.urlPathEncode(str) 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

SP.Utilities.HttpUtility Methods

SP.Utilities Namespace