SPAlertCollection.Item 属性 (Int32)

获取集合中指定索引处的警报。在 C# 中,此属性是SPAlertCollection类的索引器。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
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
    类型:System.Int32

    一个 32 整数,它指定的索引。

属性值

类型:Microsoft.SharePoint.SPAlert
此警报表示Microsoft.SharePoint.SPAlert对象。

备注

如果指定的索引的索引集合的有效范围, Item属性将引发ArgumentOutOfRangeException 。

示例

下面的代码示例循环访问该集合的指定用户的警报,并使用索引器来显示每个列表项的标题和标题的列表。

本示例假定存在一个包含一个标签控件的.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

另请参阅

引用

SPAlertCollection 类

SPAlertCollection 成员

Item 重载

Microsoft.SharePoint 命名空间