SPAlertCollection.Item property (Int32)
取得集合中指定之索引處的警示。在 C# 中,這個屬性會是SPAlertCollection類別的索引子。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public ReadOnly Default Property Item ( _
index As Integer _
) As SPAlert
Get
'用途
Dim instance As SPAlertCollection
Dim index As Integer
Dim value As SPAlert
value = instance(index)
public SPAlert this[
int index
] { get; }
參數
index
Type: System.Int32指定的索引為 32 位元整數。
Property value
Type: Microsoft.SharePoint.SPAlert
Microsoft.SharePoint.SPAlert物件,表示此警示。
備註
如果指定的索引超出索引集合的有效範圍內的 [ Item ] 屬性,則會擲回ArgumentOutOfRangeException 。
Examples
下列程式碼範例會逐一查看集合的指定使用者的提醒,並使用索引子顯示每個清單項目的標題,其清單的標題。
此範例假設包含的標籤控制項的.aspx 網頁的存在。
Dim site As SPSite = SPControl.GetContextSite(Context)
Dim web As SPWeb = site.AllWebs("Site_Name")
Dim alerts As SPAlertCollection = web.Users("User_Loggin_Name").Alerts
Dim i As Integer
For i = 0 To alerts.Count - 1
Label1.Text += SPEncode.HtmlEncode(alerts(i).Title) + "<BR>"
Next i
SPSite oSiteCollection = SPContext.Current.Site;
SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"];
SPAlertCollection collAlerts = oWebsite.Users["Username"].Alerts;
for (int intIndex=0; intIndex<collAlerts.Count; intIndex++)
{
Label1.Text += SPEncode.HtmlEncode(collAlerts[intIndex].Title) + "<BR>";
}
oWebsite.Dispose();
注意事項 |
---|
某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects。 |