Monday, December 8, 2008

SharePoint Alert customization

Recently i was working on customizing SharePoint alerts. Sharing different things i learnt while working on this:
You can create one or more alerts for a list or document library in a SharePoint site. When creating alerts you have option of what event and when to get notified. Alerts can be managed by Administrators or Users. SharePoint object model provides methods to manage Alerts programmatically.

SPAlert class provides details on alert like alert frequency, alert type,user who created the alert. This class also provides a method to update alert details. Following code snippet shows how to create SharePoint Alert programmatically:

using (SPSite site = new SPSite("http://servername"))
{
using (SPWeb web = site.OpenWeb())
{
SPUser user = web.SiteUsers["domain name\\username];
SPAlert newAlert = user.Alerts.Add();
newAlert.AlertType = SPAlertType.List;
newAlert.List = web.Lists["List Name"];
newAlert.EventType = SPEventType.All;
newAlert.AlertFrequency = SPAlertFrequency.Immediate;
//passing true to Update method will send alert confirmation mail
newAlert.Update(false);
}
}

SharePoint stores the alert information like web application URL and List URL in content database. Because of this, the links inside alert mail will break if web application URL or List URL is changed. To fix this user need to update the alert manually from alert manager or Administrator can run a script to update alerts. Refer this link for more details on this issue.

Alert mails can be customized in two ways:
Approach 1
You can customize the Alert tempaltes of WSS. Alert tempaltes are located in
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\XML\AlertTemplates.xml"
Following link has lot of details on this approach:
http://blogs.msdn.com/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx

Approach 2
You can also customize alert mail format by implementing IAlertNotifyHandler interface. Following Microsoft KB article has details on this:
http://support.microsoft.com/kb/948321/en-us

How to debug custom alert handlers
Alerts are generated by WSS timer job. Time job reads the event log and sends the alert. So to debug custom alert handlers you need to attach timer process to debugger (OWSTIMER.exe).

Though we can customize alert mail format, i dint find a way to customize the alert confirmation mail format.

5 comments:

Anonymous said...

I have an issue in the debug. When I use the dll for two webapplications, in the debug, the process is not running to the end. the 1st alert launch 4 stpes then the 2nd alert begin to launch. Then the 1st alert take place with the value in the 2nd alert. the message is 'The process or thread changed since the last step'. Does anyone has the same problem?

Anonymous said...

Nice blog you got here. I'd like to read something more concerning that matter. The only thing I would like to see here is some pictures of any gadgets.
Jeff Karver
Cell phone jammer

Dean said...

greetings to all.
I would first like to thank the writers of this blog by sharing information, a few years ago I read a book called Real Estate Investment costa rica in this book deal with questions like this one.

niz said...

Hello .. firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Generic Viagra in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.

Kevin Marshall said...

I like this post because it is very very interesting.Thanks you very much for sharing this article.


Web Services