0 out of 1 rated this helpful - Rate this topic

SPEncode.HtmlEncode Method

Encodes the specified string so that special characters used in HTML are encoded as HTML entities.

Namespace:  Microsoft.SharePoint.Utilities
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
public static string HtmlEncode(
	string str
)

Parameters

str
Type: System.String
The string to encode.

Return Value

Type: System.String
The encoded version of the string that is passed to the method.

The HtmlEncode method converts characters to entities as follows:

  • < to &lt;

  • > to &gt;

  • & to &amp;

  • " to &quot;

  • ' to &#39;

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Simple sample
A simple sample of using this code would be:

var encodedString = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(stringToEncode);