Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a daily summary alert for any change in a SharePoint site

I recently got the requirement for a person to receive a daily summary alert for any change within a SharePoint site; each site has an owner who is in charge of the content on their site.

The current way we have something working is to automatically set up alerts for every list/library within the site.

// Get the Lists on this Site
SPListCollection siteLists = currentSite.Lists;
foreach (SPList list in siteLists)
{
    if (!list.ToString().Equals("Master Page Gallery"))
    {
        if (list.ReadSecurity == 1) // user has read access to all items
        {
            // Create an Alert for this List
            Guid alertID = currentUser.Alerts.Add(list, SPEventType.All, SPAlertFrequency.Daily);

            // Set any additional properties
            SPAlert newAlert = currentUser.Alerts[alertID];
        }
    }
}

This creates two problems:

  1. The user has a lot of different alerts created. Ideal: Only ONE email with the daily summary.
  2. Some sort of monitor would have to be set up to check for new lists or libraries in the site and automatically set up alerts for the user.

Q: How can I create a daily summary alert for all changes in a site?

like image 290
Kit Menke Avatar asked May 28 '09 15:05

Kit Menke


1 Answers

I believe the solution you're looking for is available through the auditing framework. Auditing is very robust in SP, unfortunately it's easy to get overwhelmed by the output.

The Audit is a property available on the SPSite, SPWeb, SPList, and SPItem properties.

Adjust the specific audit flags (using the .Audit.AuditFlags properties) using this property to suite your needs (the specifics will depend on how you define "change" but almost anything you can think of is available).

Details about the SPAudit object are available on MSDN.

Once you've defined what/where you want to audit, you'll have to get that information back to your users.

By default, SP sets up some nice reports that available at the site collection level ([url of site collection]/_layouts/Reporting.aspx?Category=Auditing). These may meet your needs.

Your initial solution mentioned alerts via email for the users. Given that most users want to centralize their information in email (though their MySite is great place to put a link to the reports!) you'll have a little more work to do.

You can pull the required audit information through the object model using the SPAuditQuery and SPAuditEntryCollection objects. Again, MSDN has some information on how to use these objects.

I would recommend setting up a custom SPJobDefinition that runs at the end of the day to email the users the audit report for their site. Andrew Connell has a great explaination of how to setup a custom job on his blog.

To summarize:

  • enable auditing for the SPWeb's in question
  • create a report using SPAuditQuery and SPAuditEntryCollection for each SPWeb
  • create an SPJobDefinition that runs each night to email the report to each SPWeb owner
like image 71
Mark Avatar answered Oct 06 '22 21:10

Mark