Share via


SPAlertCollection.Add method (SPList, SPEventType, SPAlertFrequency, SPAlertDeliveryChannels)

Adds an alert for a list to the collection.

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

Syntax

'Declaration
Public Function Add ( _
    list As SPList, _
    eventType As SPEventType, _
    alertFrequency As SPAlertFrequency, _
    deliveryChannels As SPAlertDeliveryChannels _
) As Guid
'Usage
Dim instance As SPAlertCollection
Dim list As SPList
Dim eventType As SPEventType
Dim alertFrequency As SPAlertFrequency
Dim deliveryChannels As SPAlertDeliveryChannels
Dim returnValue As Guid

returnValue = instance.Add(list, eventType, _
    alertFrequency, deliveryChannels)
public Guid Add(
    SPList list,
    SPEventType eventType,
    SPAlertFrequency alertFrequency,
    SPAlertDeliveryChannels deliveryChannels
)

Parameters

Return value

Type: System.Guid
The ID of the alert.

Remarks

Use of the Add method sends a confirmation notice to each user telling them that they have successfully added an alert.

The following code example creates a daily alert for every user of a SharePoint site whenever the Announcements list is modified.

Dim web As SPWeb = SPControl.GetContextWeb(Context)
Dim users As SPUserCollection = web.Users
Dim list As SPList = web.Lists("Announcements")
Dim user As SPUser

For Each user In  users

    user.Alerts.Add(list, Microsoft.SharePoint.SPEventType.Modify, 
        Microsoft.SharePoint.SPAlertFrequency.Daily, Microsoft.SharePoint.SPAlertDeliveryChannels.Email)

Next user
SPWeb oWebsite = SPContext.Current.Web;
SPUserCollection collUsers = oWebsite.Users;
SPList oList = oWebsite.Lists["Announcements"];
foreach (SPUser oUser in collUsers)
{
   oUser.Alerts.Add(oList, Microsoft.SharePoint.SPEventType.Modify, 
      Microsoft.SharePoint.SPAlertFrequency.Daily, Microsoft.SharePoint.SPAlertDeliveryChannels.Email);
}

See also

Reference

SPAlertCollection class

SPAlertCollection members

Add overload

Microsoft.SharePoint namespace