SPAlert Class (Microsoft.SharePoint)
SPAlert Class (Microsoft.SharePoint)
Represents an alert, which generates periodic e-mail notifications sent to a user about the list, list item, document, or document library to which the alert applies. 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.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

'Usage

Dim instance As SPAlert


'Declaration

<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
Public NotInheritable Class SPAlert
Remarks

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. For example, if the collection is assigned to a variable named collAlerts, use collAlerts[index] in C#, or collAlerts(index) in Visual Basic, where index is either the index number of the alert in the collection or the display name of the alert.

NoteNote:

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

Example

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 
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 Best Practices: Using Disposable Windows SharePoint Services Objects.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPAlert
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

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View