tags:

views:

22

answers:

1

I'm trying to compile a list of all the activity for an entire site collection for a span time of, say the last 60 minutes or last 24 hours. Activity being anything that has been modified/created/rated, etc. and what user did it. One way is to brute force traverse down all of the webs, then lists, then items and find what has changed or has been created. For example:

    foreach(SPWeb web in site.AllWebs)
{
   foreach(SPList list in web.Lists)
   {
    foreach(SPListItem item in list.GetItems())
    {
        // log what has been created/modified
    }
   }
}

But there must be a better, more efficient approach. Is there somewhere that logs all activity for the last 24 hours? Is there something in the database I can hit (read only of course) that would show all of this activity.

A: 

This will give you everything that has been created or modified within the last day:

SPSiteDataQuery query = new SPSiteDataQuery();
query.Webs = "<Webs Scope=\"Recursive\" />";
query.Query = "<Where><Gt><FieldRef Name='Modified' /><Value Type='DateTime'><Today OffsetDays='-1' /></Value></Gt></Where>"
query.Lists = "<Lists BaseType=\"0\" />"; // for doc libs use: "<Lists BaseType=\"1\" />"
DataTable dt = web.GetSiteData(query);

This can be expanded to query variable time spans (and possibly to include ratings?).

Rich Bennema
Excellent. I will try this out on monday. I knew a simpler method existed.
Shane
This worked just as you suggested Rich. I still ended up hitting the database directly (read only) since I need to go through all My Sites. Each My site, as you know, is it's own site collection, so I was having to iterate in the thousands. Thanks. Accepting Answer.
Shane