Using SPAlert in SharePoint
In SharePoint Alerts are very important ,alert can be an email message send to end user or it may be Short Message Service(SMS) from the SharePoint.In many situations it is required to configure alerts for the Lists/Libraries in SharePoint.
For example let us say you have a Quality Assurance SharePoint Site which has a document library related to documents about the process and other documents,and it is a mandatory to all the employees to follow the Quality process and even if there is any change or added new process,in this it is required for employee to alert if there is any modifications/added any new documents to this library.
Using SharePoint Model it is possible to know about the user's alerts using SPAlert class.
The Following code samples shows how to user's alert using SPAlert class.
SPSite mySiteCollection=null;
SPWeb mySPweb=null;
Try
{
//Get the SPSite by passing the url
mySiteCollection = new SPSite("http://QualityAssuranceSite /")
mySPweb = mySiteCollection.OpenWeb("Quality")
SPUserCollection users = mySPweb .Users;
//Iterate through each users in site
foreach (SPUser user in users)
{
//Get alerts collections for the individual user
SPAlertCollection alerts = user.Alerts;
foreach (SPAlert alert in alerts)
{
// you can access the properties and methods from the alert object "alert"
//Title
string alertTitle=alert.Title;
//AlertFrequency
alert.AlertFrequency = Microsoft.SharePoint.SPAlertFrequency.Immediate;
alert.Update();
}
}
}
Catch(SPExecption exception)
{
Throw exception
}
Finally
{
mySiteCollection.Dispose();
mySPweb.Dispose();
}
Property Name
|
More Information/Description
|
AlertTemplate
|
Gets or sets the alert template which defines the content and format
of an alert message which can be an e-mail version of the alert, it also defines
the style and rendering.
|
AlertTemplateName
|
The alert template name.
|
AlertTime
|
Date and time for sending the alert.
|
AlertType
|
Which can be a list or document library, a list item or document, or
a custom object?
|
AlwaysNotify
|
It can be a daily or weekly alert is always sent, even if there is no
matching event.
|
DeliveryChannels
|
The delivery method of the alert.
|
DynamicRecipient
|
It defines the event data to used to populate the e-mail recipient
field in the alert.
|
EventType
|
Type of event to which the alert applies.
|
ID
|
ID of the alert.
|
Item
|
The list item or document to which the alert applies.
|
ItemID
|
The list item or document to which an alert applies in the parent
collection of list items.
|
List
|
The list or document library to which the alert applies.
|
ListID
|
The GUID of the list or document library to which the alert applies.
|
ListUrl
|
The site-relative URL of the list to which the alert applies.
|
MatchId
|
Gets or sets the pre-filtering GUID for an externally matched alert.
|
UserId
|
Gets or sets the ID of the user who created the alert.
|
No comments:
Post a Comment