共用方式為


SPHttpUtility.HtmlUrlAttributeEncode Method (String, TextWriter)

Encodes the specified string for use as an attribute value for URL type attributes, such as the href attribute of an anchor tag or the src attribute of an image tag, and appends it to the specified output stream.

Namespace:  Microsoft.SharePoint.Utilities
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Shared Sub HtmlUrlAttributeEncode ( _
    urlAttributeToEncode As String, _
    output As TextWriter _
)
'Usage
Dim urlAttributeToEncode As String
Dim output As TextWriterSPHttpUtility.HtmlUrlAttributeEncode(urlAttributeToEncode, _
    output)
public static void HtmlUrlAttributeEncode(
    string urlAttributeToEncode,
    TextWriter output
)

Parameters

  • output
    Type: System.IO.TextWriter

    A T:System.IO.TextWriter object that represents the output stream in which to append the encoded string.

Exceptions

Exception Condition
ArgumentException

The protocol of the URL parameter is not allowed.

Remarks

The HtmlUrlAttributeEncode method checks the URL protocol and, if the URL is relative or has an allowed protocol, encodes the string for use as an attribute value. It does not encode the path or query string of the URL. If you are building a URL, call UrlPathEncode and UrlKeyValueEncode separately before you call this method.

See Also

Reference

SPHttpUtility Class

SPHttpUtility Members

HtmlUrlAttributeEncode Overload

Microsoft.SharePoint.Utilities Namespace