How to set SPAlert.AlertTemplate property on an alert using SharePoint V3 API?

  • Thread starter Thread starter kashif
  • Start date Start date
K

kashif

Hello All,
I am trying to crete alerts using SharePoint V3 API and so far I am
able to create alerts but for some reason I could not figure out how to
set AlertTemplate property on SPAlert object.

Here is my code.

sPAlert = sPUser.Alerts.Add();
sPAlert.AlertType = SPAlertType.List;
sPAlert.AlertTemplate = sPAlertTemplate;
sPAlert.Title = "test alert";
sPAlert.EventType = SPEventType.Delete;
sPAlert.EventTypeBitmask = 2;
sPAlert.AlertFrequency = SPAlertFrequency.Weekly;
sPAlert.User = sPUser;
sPAlert.List = sPList;
sPAlert.Update();


I did try following steps to make it work but after the update it still
shows null for this property. You know if do not set this property then
no body can see the nice looking email.

SPAlertTemplate sPAlertTemplate = new SPAlertTemplate();

sPAlert.AlertTemplate = sPAlertTemplate;


Can some body help me figure out how to set this property.

Thanks
 
You have to set the name of the template you want to use, the correct code
would be:

SPAlertTemplate sPAlertTemplate = new SPAlertTemplate();
sPAlertTemplate.Name = "SPAlertTemplateType.DocumentLibrary";

sPAlert.AlertTemplate = sPAlertTemplate;

where "SPAlertTemplateType.DocumentLibrary" is the template for document
libraries, but you can use others as well, as long as they've been registered
on your site as valid templates.

Jerome
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top