Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Creating Alerts in code

  Asked By: Rachel    Date: Sep 28    Category: Sharepoint    Views: 743

Because I had some problems with setting up alerts and because there
wasn't an answer to be found anywhere, I thought I'd post this:

The error message I was getting:
"the page you selected contains a list that does not exist"

Background: In code, I needed to create a site from a template and
add an alert to a document library based on what was fillled out in
an Infopath form. Two painful things I learned:

1. Add the alert to the web
2. Set the alert type immediately after the "Add"

Here's what works:

string docLibName = "Document Library Name";
SPList DocLib = ProjectSite.Lists[docLibName];
SPAlert alert = ProjectSite.Alerts.Add();
alert.AlertType = SPAlertType.List;
alert.Title = "Alert Title";
alert.EventType = SPEventType.All;
alert.AlertFrequency = SPAlertFrequency.Daily;
alert.User = developer;
alert.List = DocLib;
alert.Status = SPAlertStatus.On;



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on Creating Alerts in code Or get search suggestion and latest updates.