다음을 통해 공유


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)
Available in Sandboxed Solutions: No
Available in SharePoint Online

Syntax

'Declaration
<SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.PerSpec)> _
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)
[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.PerSpec)]
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