How do I find all activity in a certain time span for entire site collection, such as last 24 hours?
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 tra开发者_运维技巧verse 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.
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?).
精彩评论