SPItemEventProperties class
包含清單項目事件的相關資訊。
Inheritance hierarchy
System.Object
Microsoft.SharePoint.SPEventPropertiesBase
Microsoft.SharePoint.SPItemEventProperties
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
<SerializableAttribute> _
Public NotInheritable Class SPItemEventProperties _
Inherits SPEventPropertiesBase _
Implements IDisposable
'用途
Dim instance As SPItemEventProperties
[SerializableAttribute]
public sealed class SPItemEventProperties : SPEventPropertiesBase,
IDisposable
備註
SPItemEventProperties類別會保留項目事件,包括例如事件型別、 使用者名稱和 URL ; 該事件的固定的屬性的相關資訊它也包含Before和After屬性為其內容可供使用時,會觸發事件的清單項目。After事件Before和After屬性的定義很簡單: Before屬性參照到事件發生之前的設定和After屬性參照到存在於事件發生之後的設定。Before事件,不過, Before屬性參照到目前的項目設定之前在事件發生時After屬性參照到項目必須在事件發生之後的設定。
Examples
下列程式碼範例會使用SPItemEventProperties類別,來限制可以加入至清單的項目數目。
using System;
using Microsoft.SharePoint;
namespace Example_Namespace
{
public class Class_Name : SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
using(SPWeb oWebsite = new SPSite(properties.SiteId).OpenWeb(properties.RelativeWebUrl))
{
SPListItemCollection collItems = oWebsite.Lists[properties.ListTitle].Items;
if (collItems.Count > 150)
{
properties.Cancel = true;
properties.ErrorMessage = "Adding items to this list is not supported because it already contains " +
colItems.Count.ToString() + " items.";
}
}
}
}
}
Imports System
Imports Microsoft.SharePoint
Namespace Example_Namespace
Public Class Class_Name
Inherits SPItemEventReceiver
Public Overrides Sub ItemAdding(ByVal properties As SPItemEventProperties)
Using oWebsite As SPWeb = New SPSite(properties.SiteId).OpenWeb(properties.RelativeWebUrl)
Dim collItems As SPListItemCollection = oWebsite.Lists(properties.ListTitle).Items
If collItems.Count > 150 Then
properties.Cancel = True
properties.ErrorMessage = "Adding items to this list is not supported because it already contains " & colItems.Count.ToString() & " items."
End If
End Using
End Sub
End Class
End Namespace
注意事項 |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |
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.