2

I am using the .NET Client Object Model from a website to access data in a SharePoint list. One of the fields I am trying to access is a lookup field. How do I get the text for the lookup field using a join in the CAML query?

I have read so far that joins are not supported in CAML in the Client Object Model. Is this true?

The issue is doctype comes back with a message saying it is a lookup field.

It is not possible for me to use the SharePoint Server Object Model.

Here is a snippet of what I am doing:

ClientContext _clientContext = new ClientContext(ConfigurationManager.AppSettings["SPServer_DigAssts"].ToString());

List list = _clientContext.Web.Lists.GetByTitle("Leases");
CamlQuery camlQuery = new CamlQuery();

camlQuery.ViewXml = "@<View><Query><Where><Eq><FieldRef Name='BuildingId'/><Value Type='Text'>" + bid.ToString() + "</Value></Eq></Where></Query></View>";

ListItemCollection listItems = list.GetItems(camlQuery);

_clientContext.Load(listItems, items => items.Include(item => item["BuildingId"], item => item["DocType"], item => item.DisplayName));

_clientContext.ExecuteQuery();

foreach (ListItem listItem in listItems) 
{
    DataRow r = dtbl.NewRow();
    r["BuildingId"] = listItem["BuildingId"];
    r["Name"] = listItem.DisplayName;
    r["DocType"] = listItem["DocType"];
    dtbl.Rows.Add(r);
}
  • What is the error you are receiving? – RJ Cuthbertson Sep 4 '13 at 23:59
1

Use following code to read the lookupvalue

var docType= listItem["DocType"] as Microsoft.SharePoint.Client.FieldLookupValue;
string value = docType.LookupValue;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.