HttpUtility.HtmlEncode Method

Converts a text string into an HTML-encoded string.

Namespace:  System.Net
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function HtmlEncode ( _
    html As String _
) As String
[SecuritySafeCriticalAttribute]
public static string HtmlEncode(
    string html
)

Parameters

Return Value

Type: System.String
An HTML-encoded string.

Remarks

An HTML document consists of text and control characters. Control characters cannot be displayed directly unless they are HTML-encoded.

For example, to display the character < (less than sign) in your HTML document, you must use the character sequence &lt;. Otherwise, it will be interpreted as the beginning of an HTML tag.

This method performs the following conversions to character-entity equivalents:

  • < to &lt;

  • > to &gt;

  • & to &amp;

  • " to &quot;

Version Information

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.