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)
Available in Sandboxed Solutions: No
Available in SharePoint Online
Syntax
'Declaration
<SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.PerSpec)> _
Public Function Add ( _
item As SPListItem, _
eventType As SPEventType, _
alertFrequency As SPAlertFrequency, _
deliveryChannels As SPAlertDeliveryChannels _
) As Guid
'Usage
Dim instance As SPAlertCollection
Dim item As SPListItem
Dim eventType As SPEventType
Dim alertFrequency As SPAlertFrequency
Dim deliveryChannels As SPAlertDeliveryChannels
Dim returnValue As Guid
returnValue = instance.Add(item, eventType, _
alertFrequency, deliveryChannels)
[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.PerSpec)]
public Guid Add(
SPListItem item,
SPEventType eventType,
SPAlertFrequency alertFrequency,
SPAlertDeliveryChannels deliveryChannels
)
Parameters
item
Type: Microsoft.SharePoint.SPListItemA Microsoft.SharePoint.SPListItem object that represents the item 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 e-mail 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 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.
Dim web As SPWeb = SPControl.GetContextWeb(Context)
Dim list As SPList = web.Lists("Shared Documents")
Dim item As SPListItem = list.Items(1)
Dim users As SPUserCollection = web.Users
Dim user As SPUser
For Each user In users
user.Alerts.Add(item, Microsoft.SharePoint.SPEventType.Discussion,
Microsoft.SharePoint.SPAlertFrequency.Immediate, Microsoft.SharePoint.SPAlertDeliveryChannels.Email)
Next user
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);
}