共用方式為


SPEncode class

提供方法讓編碼字串。

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Utilities.SPEncode

Namespace:  Microsoft.SharePoint.Utilities
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class SPEncode
'用途
Dim instance As SPEncode
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SPEncode

備註

使用方法SPEncode類別中為預防安全性問題可協助防止惡意指令碼區塊執行跨網站的應用程式中執行。

您不需要執行個體化SPEncode類別,因為它的方法是靜態的使用方式。

在程式碼會呼叫Microsoft.SharePoint組件內的成員, SPEncode類別的編碼方法會更有效率比**[System.Web.HttpUtility][System.Web.HttpServerUtility]類別的方法。要編碼的字元比[System.Web.HttpUtility][System.Web.HttpServerUtility]**類別中方法較大組可用SPEncode類別中的 Url 與 HTML 編碼的方法。

Examples

下列範例會將指定的字串轉換成"Please respond by &lt;B&gt;Friday&lt;/B&gt;"中,使瀏覽器顯示請以回應 < B > 星期五 < /B >

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

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

SPEncode.WriteHtmlEncode(myString);

Thread safety

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

請參閱

參照

SPEncode members

Microsoft.SharePoint.Utilities namespace