Mailing List


Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To Gmail
Voicemail To Gmail

How Long For Me


NerdyHearn - Blog

<< Back To All Blogs

Retrieving User Name and MetaData through WCF Web Services for SharePoint 2010

Monday, March 4th, 2013

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(""));
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.

WCFin' Tom Out.



Related Blogs

Determining if MOSS is Standard or Enterprise
Automatically Setting File Name in SharePoint when submitting an InfoPath 2007 Form
SharePoint Web Services, .NET 3.5, and Authentication Issues
First Version of SharePoint Validator now available on CodePlex
Fixing "The given key was not present in the dictionary" error in SharePoint 2010 Installation


bbo said on Monday, August 26th, 2013 @ 6:09 AM

IMHO it is because of the lazy loading strategy of the ADO.NET Data Services technology. This article was usefull for me:

Add A Comment



Email Address: (not public, used to send notifications on further comments)


Enter the text above, except for the 1st and last character:

NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers