Introduction:SharePoint 2010 provides the capability to subscribe the content through a feature called "Alerts". Alerts can be subscribed for at one of the four levels list, document library, list item and document. This also enables you to be notified by e-mail of any changes made to the content of your SharePoint Web site. In this article we will be seeing how to create an alert for a particular user and for a specified document library using the SharePoint object model.For configuring alerts in SharePoint 2010 through out of the box refer to my previous article http://www.c-sharpcorner.com/UploadFile/anavijai/7593/ (Copy and paste the hyperlink).SPAlert Class:This class is used to represent an alert, which generates periodic e-mail or Short Message Service (SMS) notifications sent to a user about the list, list item, document, or document library to which the alert applies. Using this class we will be creating a new alert for a document library.Steps involved:
namespace Alerts{ class Program { static void Main(string[] args) { using (SPSite site = new SPSite("http://serverName:22222/sites/TestSite/")) { using (SPWeb web = site.RootWeb) { SPList list=web.Lists.TryGetList("Shared Documents"); SPUser user = web.EnsureUser(@"domainName\userName"); SPAlert newAlert = user.Alerts.Add(); newAlert.Title = "My Custom Alert"; newAlert.AlertType=SPAlertType.List; newAlert.List = list; newAlert.DeliveryChannels = SPAlertDeliveryChannels.Email; newAlert.EventType = SPEventType.Add; newAlert.AlertFrequency = SPAlertFrequency.Immediate; newAlert.Update(); } } } }}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: