R – Getting the SPWeb for a SPAuditEntry

mosssharepointsharepoint-2007

I'm currently building an app that will parse all of the Audit entries in a site collection and send out a pretty email to users.

My problem is that the emails should be based on a particular web (essentially an email summarizing the changes that happened to each subsite). Apparently, there is no information in the SPAuditEntry object about the web it came from except for the DocLocation property.

This means I can get any of the following DocLocations (ItemType = Document, Event = Update):

  • sites/MySiteCollection/Documents/This is a test.doc
  • sites/MySiteCollection/Reporting Templates/audit.xml
  • sites/MySiteCollection/Lists/Reporting Metadata/1_.000
  • sites/MySiteCollection/MySubSite1/Lists/Announcements/2_.000
  • sites/MySiteCollection/MySubSite1/Template Documents/SampleTestEmail.doc

I'm thinking I can probably figure out the web from the URL by using SPSite.AllWebs.Names if I have to.

Q: How do I figure out which SPWeb a particular SPAuditEntry comes from?

Best Answer

I might have something (very crude), but it kinda depends on how deep your sub webs are nested. Are they just 1 level deep (i.e. site/web1, site/web2 or site/web1/web1_1 etc.). And have you looked if the SPAuditEntry objects have a ScopeId in their EventData xml? Found an article that describes kinda the same as you that uses the ScopeId from the EventData xml to do some matching:

Article

Also, the following post describes using the ItemId (guid) in an SPSiteDataQuery to retrieve the item, then uses the resulting data (WebId and ListId) to open a specific web / list. Might be a bit inefficient to retrieve an item at a time but it something...

Post

Related Topic