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)

public Guid Add(
	SPList list,
	SPEventType eventType,
	SPAlertFrequency alertFrequency,
	SPAlertDeliveryChannels deliveryChannels


Type: Microsoft.SharePoint.SPList

A Microsoft.SharePoint.SPList object that represents the list to which the alert applies.

Type: Microsoft.SharePoint.SPEventType

A Microsoft.SharePoint.SPEventType value that specifies the event type for the alert.

Type: Microsoft.SharePoint.SPAlertFrequency

A Microsoft.SharePoint.SPAlertFrequency value that specifies the frequency for sending an alert.

Type: Microsoft.SharePoint.SPAlertDeliveryChannels

A value that specifies whether the alert is delivered as email or as a Short Message Service (SMS) message.

Return value

Type: System.Guid
The ID of the alert.

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.

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);