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

Adds an alert for a list item to the collection.

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

public Guid Add(
	SPListItem item,
	SPEventType eventType,
	SPAlertFrequency alertFrequency,
	SPAlertDeliveryChannels deliveryChannels


Type: Microsoft.SharePoint.SPListItem

A Microsoft.SharePoint.SPListItem object that represents the item 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 e-mail 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 message to each user telling them they have successfully added an alert.

The following code example creates an alert for every user of a site. This alert immediately notifies them whenever a user discusses a specified file in the Shared Documents document library.

SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["Shared Documents"];
SPListItem oItem = oList.Items[1];
SPUserCollection collUsers = oWebsite.Users;
foreach (SPUser oUser in collUsers)
   oUser.Alerts.Add(oItem, Microsoft.SharePoint.SPEventType.Discussion, 
      Microsoft.SharePoint.SPAlertFrequency.Immediate, Microsoft.SharePoint.SPAlertDeliveryChannels.Email);