SPAlertCollection.Item Property (Int32)
Gets the alert at the specified index in the collection. In C#, this property is an indexer for the SPAlertCollection class.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public ReadOnly Property Item ( _
index As Integer _
) As SPAlert
Get
'Usage
Dim instance As SPAlertCollection
Dim index As Integer
Dim value As SPAlert
value = instance.Item(index)
public SPAlert this[
int index
] { get; }
Parameters
index
Type: System.Int32A 32-bit integer that specifies the index.
Property Value
Type: Microsoft.SharePoint.SPAlert
A Microsoft.SharePoint.SPAlert object that represents the alert.
Remarks
The Item property throws an ArgumentOutOfRangeException if the specified index is outside the valid range of indices for the collection.
Examples
The following code example iterates through the collection of alerts for a specified user and uses the indexer to display the title of each list item and the title of its list.
The example assumes the existence of a .aspx page that contains a label control.
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();
Note
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.