Thursday 15 May 2014

SharePoint Client Object Model get Look up field

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
namespace SPLookUpPOC
{
class Program
{
static void Main(string[] args)
{
string strWeburl = "http://MyServer/sites/MyWebSite";
ClientContext ObjContext = new ClientContext(strWeburl);
List Objlist = ObjContext.Web.Lists.GetByTitle("MyList");
CamlQuery ObjQuery = new CamlQuery();
ObjQuery.ViewXml = @"<View Scope='RecursiveAll'/>";
ListItemCollection objListColl = Objlist.GetItems(ObjQuery);
ObjContext.Load(objListColl);
ObjContext.ExecuteQuery();
//Now we can loop all columns from ListItemCollection..I am trying to find lookup column
string strID = string.Empty;
foreach (ListItem objItem in objListColl)
{
if (objItem["ID"] != null)
{
FieldLookupValue Objlf = (FieldLookupValue)objItem.FieldValues["ID"];
strID = Objlf.LookupId.ToString();
}
}
}
}
}