kamagra how much to take

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:

  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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>