We have been writing some automated jobs at work to pull user data and compare against Active Directory using WCF services for SharePoint.

The important part of working with Active Directory, is of course, the dreaded username (aka sAMAccountName).

We noticed that when we pulled user information from a list the ModifiedBy, CreatedBy, etc were all blank. They did, however, have a ModifiedById and CreatedById which was a single integer.

As it turns out, there is a list in the DataContext called UserInformationList which can be used to pull users based on their ID.

See the example below:

MyNamespace.MyDataContext dc = new MyNamespace.SiteDataContext(new Uri("http://sharepoint.nerdyhearn.com/sites/departments/mydepartment/_vti_bin/ListData.svc/"));
dc.Credentials = System.Net.CredentialCache.DefaultCredentials;

var mylist = dc.MyList;

// I like hard-typed lists for user information instead of var-based data
List<MyNamespace.UserInformationListItem> allSPUsers = dc.UserInformationList.ToList<MyNamespace.UserInformationListItem>();

foreach (var listItem in mylist) {
    int modifiedById = listItem.modifiedById;

    UserInformationListItem allUserData = (from usercheck in allSPUsers
        where usercheck.Id.Equals(modifiedById)
        select usercheck).FirstOrDefault<UserInformationListItem>();
        
    string username = allUserData.UserName;
    string name = allUserData.Name;
    // more properties to be read here
}

Simple enough, but Googling didn’t help me much on this, so figured I’d share