Export (0) Print
Expand All

SPAlertCollection.Item Property (Guid)

Gets the alert with the specified GUID from 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[
	Guid idAlert
] { get; }

Parameters

idAlert
Type: System.Guid

A GUID that identifies the item.

Property Value

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

The following code example iterates through all the alerts on a site for a specified user, generates an array to store the GUID of each alert, and then uses each GUID to display the frequency and event type for each alert.

SPSite oSite = SPContext.Current.Site;
SPWebCollection collWebsites = oSite.AllWebs;
foreach (SPWeb oWebsite in collWebsites)
{
    SPAlertCollection collAlerts = oWebsite.Alerts;

    foreach (SPAlert oAlert in collAlerts)
    {
        Label1.Text = SPEncode.HtmlEncode(oWebsite.Title) + " :: " +
            SPEncode.HtmlEncode(oAlert.Title) + " :: " +
        oAlert.User.LoginName + "<BR>";
    }
    oWebsite.Dispose();
}
NoteNote

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.

Show:
© 2014 Microsoft