Getting List Items using WCF and Sharepoint 2010

574 Views Asked by At

I am attempting to loop through all the items in a sharepoint List and get the firstname of the requestor.

Requestor is a UserInformationListItem type

var source = dc.Requests;

listBox1.Items.Clear();
foreach (var user in source) {
    string name = user.Requestor.FirstName;
    listBox1.Items.Add(name);
}

The code that i'm using works fine for getting the ID's of the list items but when it comes to getting anything that would be inside a userinformationlistitem it get the error "Object reference not set to an instance of an object".

1

There are 1 best solutions below

0
TurtleTopiary On

Found the Solution:

var requestedBy = dc.UserInformationList.Where(i => i.Id == user.RequestorId).FirstOrDefault();
var requestedByUserID = requestedBy.UserName;
listBox1.Items.Add(requestedByUserID);