Share via


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)

Syntax

'Declaration
Public ReadOnly Default Property Item ( _
    idAlert As Guid _
) As SPAlert
    Get
'Usage
Dim instance As SPAlertCollection
Dim idAlert As Guid
Dim value As SPAlert

value = instance(idAlert)
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.

Examples

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.

Dim site As SPSite = SPControl.GetContextSite(Context)
Dim web As SPWeb = site.AllWebs("Site_Name")
Dim alerts As SPAlertCollection = web.Users(TextBox1.Text).Alerts
Dim guids(alerts.Count) As System.Guid
Dim i As Integer

For i = 0 To alerts.Count - 1

    guids.SetValue(alerts(i).ID, i)

Next i

Dim j As Integer

For j = 0 To guids.Length - 1

    Label1.Text += alerts(guids(j)).AlertFrequency + "--" + 
        alerts(guids(j)).EventType + "<BR>"

Next j
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();
}

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.

See also

Reference

SPAlertCollection class

SPAlertCollection members

Item overload

Microsoft.SharePoint namespace