Getting the SPWeb for a SPAuditEntry

℡╲_俬逩灬. 提交于 2019-12-25 03:32:35

问题


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?


回答1:


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




回答2:


My solution is outlined below in pseudocode:

  1. Get the collection of all web names in my site collection: _allWebNames = site.AllWebs.Names;
  2. Since I only care about the top level SPWeb's inside the site, I parse the SPAuditEntry.DocLocation to get the possible web name. (Ex: will return "MySubSite1" out of "sites/MySiteCollection/MySubSite1/Lists/Announcements/2_.000")

    string webName = GetPossibleWebName(SERVER_RELATIVE_URL, docLocation);

  3. Then search my array to see if the web name matches.

    index = Array.BinarySearch<string>(_allWebNames, webName, new ServiceSiteNameComparer());

  4. If I find a match, then I can using SPSite.OpenWeb(string) to open the web and get the ID.


来源:https://stackoverflow.com/questions/1940841/getting-the-spweb-for-a-spauditentry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!