Share via


SPAlert class

Represents an alert, which generates periodic e-mail or Short Message Service (SMS) notifications sent to a user about the list, list item, document, or document library to which the alert applies.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPAlert

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public NotInheritable Class SPAlert
'Usage
Dim instance As SPAlert
public sealed class SPAlert

Remarks

SPAlert provides information about the alert, such as which alert template is used, the alert frequency, and the UserID of the user who created the alert.

Use the Alerts property of either the SPUser or SPWeb class to return an SPAlertCollection object that represents the collection of alerts for the user or Web site. Use an indexer to return a single alert from the collection.

Note

Use the Update method after making any changes to the alert.

Examples

This code example uses the SPAlert class to iterate through all the alerts for every user of a site and update the alert frequency.

Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim users As SPUserCollection = site.Users
Dim user As SPUser

For Each user In  users

    Dim alerts As SPAlertCollection = user.Alerts
    Dim alert As SPAlert

    For Each alert In  alerts

        alert.AlertFrequency = 
            Microsoft.SharePoint.SPAlertFrequency.Immediate

        alert.Update()

    Next alert

Next user 
SPWeb oWebsite = SPContext.Current.Web;
SPUserCollection collUsers = oWebsite.Users;

    foreach (SPUser oUser in collUsers)
    {
        SPAlertCollection collAlerts = oUser.Alerts;

         foreach (SPAlert oAlert in collAlerts)
         {
             oAlert.AlertFrequency =  
             Microsoft.SharePoint.SPAlertFrequency.Immediate;

             oAlert.Update();
         }
     }

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.

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also

Reference

SPAlert members

Microsoft.SharePoint namespace