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

public SPAlert this[
	int index
] { get; }


Type: System.Int32

A 32-bit integer that specifies the index.

Property Value

Type: Microsoft.SharePoint.SPAlert
A Microsoft.SharePoint.SPAlert object that represents the alert.

The Item property throws an ArgumentOutOfRangeException if the specified index is outside the valid range of indices for the collection.

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.

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>";

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.