Click to Rate and Give Feedback
Community Content
In this section
Statistics Annotations (1)
Collapse All/Expand All Collapse All
This page is specific to
The 2007 product release

Other versions are also available for the following:
SPEncode Class (Microsoft.SharePoint.Utilities)
Provides methods for encoding strings.

Namespace: Microsoft.SharePoint.Utilities
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class SPEncode
Visual Basic (Usage)
Dim instance As SPEncode
C#
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public class SPEncode

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

You do not need to instantiate the SPEncode class to use them because all its methods are static.

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

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>.

Visual Basic
Dim myString As String = "Please respond by <B>Friday</B>."

SPEncode.WriteHtmlEncode(myString) 
C#
string myString = "Please respond by <B>Friday</B>.";

SPEncode.WriteHtmlEncode(myString);
System.Object
  Microsoft.SharePoint.Utilities.SPEncode
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker