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
list
Type: Microsoft.SharePoint.SPListA Microsoft.SharePoint.SPList object that represents the list to which the alert applies.
eventType
Type: Microsoft.SharePoint.SPEventTypeA Microsoft.SharePoint.SPEventType value that specifies the event type for the alert.
alertFrequency
Type: Microsoft.SharePoint.SPAlertFrequencyA Microsoft.SharePoint.SPAlertFrequency value that specifies the frequency for sending an alert.
deliveryChannels
Type: Microsoft.SharePoint.SPAlertDeliveryChannelsA 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.
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);
}