Home
Blog
Contact
Mailing List
Software
Active Directory Products
Object Compare
Permission Compare
IPhone Products
Calls To Calendar
SMS To Gmail
Voicemail To Gmail
Sites
SaveMySerials
How Long For Me
DocuTerminal
My Music To Me
Blog
Twitter
|
<< 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
SharePoint Browser 1 Released!
Configuring Nintex Request Approval Action Permissions in SharePoint
Web form to help audit permissions in SharePoint 2007/MOSS
Receiving null value when using SPFarm.Local on SharePoint 2010
Creating a dynamic SharePoint settings DropDown using a ToolPart
Comments
Currently no comments.
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:
|