Getting new alerts for a SharePoint user in c#

1.1k Views Asked by At

I have an ASP.NET 4.0 application that is written in c#. I also have a SP2010 Foundation application that is using Claims Based Authentication.

The users do not see the SharePoint application entirely. Only library views are embeded into Iframes and a single sign on has been implemented so that when a user logs in to my application, they are also simultaneously logged into SP.

Is it possible to get all alerts for a specific user.

For example:

Jim logs into my application and sees the following: Doc A has a new modification Doc C has just been uploaded. Document B has a new modification.

So basically instead of sending an e-mail I Would like to use the SP DOM to grab all pending updates for a specific user.

Something similar to this:

SPUser user = web.EnsureUser(@"domainName\userName");
SPAlertCollection alertColl = user.Alerts;
foreach (SPAlert alert in alertColl)
{
Console.WriteLine(alert.Title); 
}

I am assuming this would give the alerts that a specific user has been assigned to. But does SharePoint store if a user has a new alert for the item that they have alerts assigned?

1

There are 1 best solutions below

0
On

When you say "does sharepoint store if a user has a new alert" are you referring to the email itself? SPAlert and SPAlertCollection are the actual objects that monitor the list item and trigger the sending of the email, the email itself is not the alert object (though I completely understand why that's confusing). As far as I know, the only way to monitor the emails is to do it through your mail server, SharePoint doesn't have an easy way of tracking that.

If I'm understanding your question correctly, you want to use your application to display any alert notifications the user has, as opposed to sending the user an email? Something like that could be accomplished by routing alert emails to an intermediary account, then having your application read/filter/display those emails. This also gives you the ability to set up rules on the emails that can organize them and send your own customized notifications (SharePoint makes it very difficult to customize the email notification templates).