NerdyHearn
Home
Blog

Contact
Mailing List

Software

Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To CSV
SMS To Gmail
Voicemail To Gmail

Sites
DocuTerminal
How Long For Me
My Music To Me
SaveMySerials
TypeCount

Blog
Twitter

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

WCFin' Tom Out.

Tags

SharePoint

Related Blogs

Configuring Nintex Request Approval Action Permissions in SharePoint
Adding a Custom ASP.NET Page to MOSS/WSS
Fixing MOSS/WSS SharePoint errors with Alternate Access Mappings
Enabling .NET Framework 3.5 in MOSS/WSS After install
Determining if MOSS is Standard or Enterprise

Comments

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:

http://blogs.msdn.com/b/stuartleeks/archive/2008/09/15/dataservicequery-t-expand.aspx

Add A Comment

Name:


URL:


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


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. DocuTerminal - Online Filing Cabinet solution. Scan, search and archive your paper documents. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers My Music To Me - Stream your subsonic music collection to your Sonos wireless system TypeCount - Count how often you type across different computers! Sipellect - Business-focused, IT-intelligent call center and online calling solutions