This documentation is archived and is not being maintained.

SPEncode Class

The SPEncode class provides methods for encoding strings.

System.Object

   Microsoft.SharePoint.Utilities.SPEncode

Public Methods

The following table shows the methods of the SPEncode class and a brief description of each.

Name Description
HtmlDecode Decodes the specified encoded string, replacing entities with HTML characters.
HtmlEncode Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser.
HtmlEncodePreserveSpaces Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser, but preserves multiple spaces.
IsLegalCharInUrl Returns a Boolean value that indicates whether the specified character is a legal character in URL protocol.
NoEncode Applies no encoding to the specified string.
ScriptEncode Encodes a string for use in script.
UrlDecodeAsUrl Decodes the encoded URL string, removing quoted UTF-8 formatting for special characters.
UrlEncode Encodes the specified string, converting special characters to quoted UTF-8 format.
UrlEncodeAsUrl(String) Encodes the specified string, converting special characters to quoted UTF-8 format, but assumes that the string is a path component of a URL.
UrlEncodeAsUrl(String, Boolean) Encodes the specified string, converting special characters to quoted UTF-8 format, but assumes that the string is a path component of a URL and encodes Unicode characters only if encodeUnicodeCharacters is true.
WriteHtmlEncode Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser and writes the string to the HTTP output content stream.
WriteHtmlEncodePreserveSpaces Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser and writes the string to the HTTP output content stream, but preserves multiple spaces within the string.
WriteHtmlEncodePreserveSpacesWithQuote Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser and writes the string to the HTTP output content stream, but preserves multiple spaces within the string and surrounds the string with quotation marks.
WriteHtmlEncodeWithQuote Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser and writes the string in quotation marks to the HTTP output content stream.
WriteNoEncode(System.Web.HttpResponse, Int32) Applies no encoding to the specified integer and writes the integer to the HTTP output content stream.
WriteNoEncode(System.Web.HttpResponse, String) Applies no encoding to the specified string and writes the string to the HTTP output content stream.
WriteNoEncode(System.Web.HttpResponse, System.Decimal) Applies no encoding to the specified decimal value and writes the value to the HTTP output content stream.
WriteNoEncodeWithQuote(System.Web.HttpResponse, Int32, Char) Applies no encoding to the specified integer and writes the integer in quotation marks to the HTTP output content stream.
WriteNoEncodeWithQuote(System.Web.HttpResponse, String, Char) Applies no encoding to the specified string and writes the string in quotation marks to the HTTP output content stream.
WriteNoEncodeWithQuote(System.Web.HttpResponse, System.Decimal, Char) Applies no encoding to the specified decimal value and writes the value in quotation marks to the HTTP output content stream.
WriteScriptEncode Encodes a string for use in script and writes the string to the HTTP output content stream.
WriteScriptEncodeWithQuote Encodes a string for use in script and writes the string in quotation marks to the HTTP output content stream.
WriteUrlEncode Encodes the specified string, converting special characters to quoted UTF-8 format, and writes the string to the HTTP output content stream.
WriteUrlEncodeAsUrl Encodes the specified string and writes it to the HTTP output content stream, converting special characters to quoted UTF-8 format, but assumes that the string is a path component of a URL.
WriteUrlEncodeAsUrlWithQuote Encodes the specified string and writes it in quotation marks to the HTTP output content stream, converting special characters to quoted UTF-8 format, but assumes that the string is a path component of a URL.
WriteUrlEncodeWithQuote Encodes the specified string, converting special characters to quoted UTF-8 format, and writes the string in quotation marks to the HTTP output content stream.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Remarks

Use the methods of the SPEncode class as a security precaution to help prevent malicious script blocks from being able to execute in applications that execute across sites.

Since all the methods of the SPEncode class are static, you do not need to instantiate the class to use them.

In code that calls members within the Windows SharePoint Services assembly, the encoding methods of the SPEncode class are more effective than methods of the System.Web.HttpUtility and System.Web.HttpServerUtility classes. The SPEncode methods for encoding URLs and HTML can be used to encode a larger set of characters than the methods of the HttpUtility and HttpServerUtility classes.

Example

The following example converts the specified string to "Please respond by &lt;B&gt;Friday&lt;/B&gt;" so that the browser displays "Please respond by <B>Friday</B>".

Requirements

Namespace: Microsoft.SharePoint.Utilities

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security

Show: