About      |       Articles      |      Services      |      Software      |      Contact

Latest Free SharePoint Software

ARB Security Solutions regularly releases free SharePoint software, including WebParts, Client Applications, Framework Extensions, and other Miscellaneous Components.
The most recent freeware is:

Title: Simple SharePoint Rollup WebPart
Date Published: 10/22/2009

Previous Two Free WebPart Releases:

SecureCenter For SharePoint

By SharePoint security integrators, for SharePoint security integrators.

SharePoint Security Assurance Program™

For externally facing SharePoint deployments, security is an acutely important deployment concern. Learn how through daily security scanning, you can ensure external business users and partners that they can collaborate in confidence!

Security Assurance WebPart:



Get Friendly User Name For SPAuditEntry UserId

I saw this post on the forums:

http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=2270146&SiteID=17

Where the user states (paraphrased):

I've been tasked with delivering a custom auditing solution in Sharepoint 2007 and become a little stuck.

Is there an easy way to translate a UserID (GUID) - returned from calling an instance of SPAuditEntry.UserID - into the corresponding SPUser.Name?

i.e.

string userName = SPUser.getNameByUserID(userID);

The long and short of the answer is, kind of. This is how I would go about it.

When doing this, you probably have a SPAuditEntryCollection that you are hydrating with entries using the SPSite.Audit.GetEntries method which takes a SPAuditQuery object as a parameter. You can build said SPAuditQuery objects by placing a SPSite object in as a parameter, then following setting the property constraints i.e. SPAuditQuery l_oQuery = new SPAuditQuery(SPSite). Therefore, you already are hydrating a SPSite reference within your code that should be available later. When looping through your SPAuditEntry objects in your SPAuditEntryCollection and trying to get the user name through the properties, the user name, as the person who asked the question alluded to, is not directly available through the properties. However, since you have your site reference, you can just do the following to get the User Name instead of the not entirely readable User Id:

C#:
  1. using (SPSite l_oSite = new SPSite("http://sharepointsecurity.com")
  2. {
  3. SPAuditQuery l_oQuery = new SPAuditQuery(l_oSite);
  4. SPAuditEntryCollection l_oReport = l_oSite.Audit.GetEntries(l_oQuery);
  5. foreach (SPAuditEntry l_oEntry in l_oReport)
  6. {
  7.  
  8. string l_strUserName = l_oSite.OpenWeb().Users.GetByID(l_oEntry.UserId).ToString();
  9. }
  10.  
  11. }

That should return the username.

  • Share/Bookmark

2 Comments »

  1. [...] Get Friendly User Name For SPAuditEntry UserId [...]

    Pingback by Links (12/4/2007) « Steve Pietrek’s SharePoint Stuff — December 4, 2007 @ 8:54 pm

  2. How about getting some extra data for a document? I haven’t been able to figure out how to get the friendly name of a document from the GUID in the SPAuditEntry.

    Comment by dirq — June 18, 2008 @ 2:18 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment