How to check if lists/webs are used
It sometimes comes handy for a SharePoint Administrator/Site Collection Administrator to see when lists/webs are used. This could help for example in a scenario where you want to see which lists/webs are actually used inside the SharePoint environment to let's say remove them or ask the site collection administrator to decide if to keep them or not. SharePoint has some out-of-the-box methods to check it but let's assume that your comany needs are not fullfilled by those because for instance you allready have a web part developed by you and want to show the web or list inside it and you just need a method of showing the date/time of the list or web to see if it's used or not. The out-of-the-box methods I am speaking about are and they should be enough for most cases :
- Site usage confirmation and deletion (http://technet.microsoft.com/en-us/library/cc262420.aspx)
- Audit Log Reports http://sharepoint.microsoft.com/Blogs/GetThePoint/Lists/Posts/Post.aspx?ID=414
Site Usage confirmation and deletion allows to define a specified amount of "inactivity" time and after that the site collection owners are informed by mail and the audit log reports will show you the changes that have happened
So what can you do from a developer point of view. You can use SPWeb.LastItemModifiedDate/SPList.LastItemModifiedDate OR you can use the Change Log by calling the GetChanges method of an SPList, SPWeb inside a SPChangeQuery class. http://msdn.microsoft.com/en-us/library/bb447511.aspx
So the question is what to use and when. Here are some pointers I found out lately and want to share
- When calling SPWeb.LastItemModifiedDate in the background we call proc_GetWebExtendedMetaData which does SELECT and then takes MAX(ALAux.Modified) from AllListsAux so actually SPWeb.LastItemModifiedDate simulates this by taking the max of all list timestamps in SQL. Changes can happen to a web outside of a list that would not increment the values processed by SPWeb.LastItemModifiedDate which makes SPWeb.LastItemModifiedDate not very reliable. The time returned is using DateTime.SpecifyKind method http://msdn.microsoft.com/en-us/library/system.datetime.specifykind.aspx. There is no timer job involved when calling SPWeb.LastItemModifiedDate. SPWeb.LastItemModifiedDate and SPList.LastItemModifiedDate provide a way to check date/time of change for items that are old (I mean here older thant 15 days - you will see below what I mean).
- The Change Log which actually means calling GetChances which is based on the EventCache table. There is a Change Log Timer Job that clears the EventCache table of entries that are older than 15 days. This value can be increased of course witht the risk that the EventCache Table will grow. So as you see using the GetChanges method you will get entries that are never as the log retention period defined so it is a good method of tracking changed only for new changes not old changes. The modified date/time can be also fetched using let's say using SPChange.Time http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spchange.time .
Job-change-log-expiration http://technet.microsoft.com/en-us/library/cc424964(v=office.12).aspx - Specifies the time schedule when the change log timer job occurs
Change Log - Removes expired entries from the change log of the Web application.http://technet.microsoft.com/en-us/library/cc678870.aspx