SPAlertCollection.Delete Method (Int32)
Deletes the alert at the specified index in the collection.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public Sub Delete ( _
index As Integer _
)
'Usage
Dim instance As SPAlertCollection
Dim index As Integer
instance.Delete(index)
public void Delete(
int index
)
Parameters
index
Type: System.Int32The index of the alert.
Exceptions
Exception | Condition |
---|---|
SPException | The alert does not exist or has just been deleted. |
ArgumentOutOfRangeException | The value of the index parameter is less than 0 or greater than the number of items in the collection. |
Remarks
This method deletes the specified alert from the database.
Examples
The following code example deletes all the alerts in a site for the specified user.
Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim users As SPUserCollection = site.Users
Dim user As SPUser
For Each user In users
If user.LoginName = TextBox1.Text Then
Dim alerts As SPAlertCollection = user.Alerts
Dim i As Integer
For i = alerts.Count - 1 To 0 Step -1
alerts.Delete(i)
Next i
End If
Next user
SPWeb oWebsite = SPContext.Current.Web;
SPUserCollection collUsers = oWebsite.Users;
foreach (SPUser oUser in collUsers)
{
if (oUser.LoginName == TextBox1.Text)
{
SPAlertCollection collAlerts = oUser.Alerts;
for (int i = collAlerts.Count - 1; i > -1; i--)
{
collAlerts.Delete(i);
}
}
}