Insert the following namespace
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
Use the following code.
ClientContext ccsite;
List listobj;
List listobj_lookup; //Object for lookup list
ListItemCollection _icoll;
public MainPage()
{
InitializeComponent();
ccsite = new ClientContext(ApplicationContext.Current.Url);
ccsite.Load(ccsite.Web);
listobj = ccsite.Web.Lists.GetByTitle("ListName");
listobj_lookup= ccsite.Web.Lists.GetByTitle("ListName"); // (LookUp List)
ccsite.Load(listobj);
CamlQuery qry = new CamlQuery();
qry.ViewXml = "<View/>";
_icoll_lookup= listobj_lookup.GetItems(qry);
ccsite.Load(_icoll_lookup);
ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(success), null);
}
private void success(object sender,ClientRequestSucceededEventArgs arg)
{
Dispatcher.BeginInvoke(datacon);
}
private void datacon()
{
//Geting Multiple List Item Record ID of lookup value
int[] recordID=new int[_icoll_lookup.Count];
int count=0;
foreach (ListItem item in _icoll_lookup)
{
if (Convert.ToString(item["ListItmeValue"]) == "YourString")
{
recordID[count] = Convert.ToInt32(item["ID"]);
count++;
}
}
//For insert Multiple Lookup value
ListItem litem = listobj.AddItem(new ListItemCreationInformation());
FieldLookupValue[] lookupobj = new FieldLookupValue[count];
for (int i = 0; i < count; i++)
{
lookupobj[i] = new FieldLookupValue{ LookupId = recordID[i] };
}
litem["ColumnName"] = lookupobj as FieldLookupValue[];
litem.Update();
ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(succed), null);
}
private void succed(object sender, ClientRequestSucceededEventArgs arg)
{
}
No comments:
Post a Comment