How to set client side object FieldLookupValues using managed.NET

I've tried setting the lookup field to the id directly. I've tried setting it to the string as shown in the sample code below. I've tried providing the specific listitem from the reference table all to no avail. I've found other examples that are close, but can't quite get things to work. How do you make a field in the record you are about to add properly reference the lookup table value (Account Manager)? And how would this be done for a multiselect (product)?

using (ClientContext context = new ClientContext(this.WebUrl))
    SecureString securePassword = new SecureString();
    foreach (char c in this.CRMPassword) { securePassword.AppendChar(c); }

    CredentialCache cc = new CredentialCache();
    NetworkCredential nc = new NetworkCredential(this.UserName, securePassword);                    

    cc.Add(new Uri(this.CRMWebUrl), "NTLM", nc);

    context.Credentials = cc;

    Web web = context.Web;

    // the list I want to add a new item to
    Microsoft.SharePoint.Client.List lstSecurityTasks = context.Web.Lists.GetByTitle("SecurityTasks");

    // Reference lists for my lookups
    Microsoft.SharePoint.Client.List lstAccounts = context.Web.Lists.GetByTitle("Products");
    Microsoft.SharePoint.Client.List lstContacts = context.Web.Lists.GetByTitle("Account Managers");

    //Add a new item in the List
    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
    Microsoft.SharePoint.Client.ListItem itemToAdd =  lstSecurityTasks.AddItem(itemCreateInfo);
    // set required fields
    itemToAdd["Title0"] = "Security Configuration Request";
    itemToAdd["Status0"] = "Not Started";
    // manually setting lookups to respective strings does NOT work?
    itemToAdd["MY_x0020_Product"] = ";#DataEntry Web 2.5;#Analytics Portal;#";
    itemToAdd["MY_x0020_Account_x0020_Manager"] = "3;#John Smith";



2 Answers 2


I think your question is related to Set Multi-Value for FieldLookup not a single value. So to set a multi-value column, you need to set a FieldLookupValue[] as array to be as the following

Get manually the ID of your lookup values. in this case, it's (DataEntry Web 2.5,Analytics Portal) and set it as an array as the following

var products = new[] { new FieldLookupValue { LookupId = 1 }, new FieldLookupValue { LookupId = 2} };
itemToAdd["MY_x0020_Product"] = products;

Note : LookupId = 1 refer to the ID of your lookup field value DataEntry Web 2.5 as you mention at your code, so that you should set it based on your current field value ID.

You can also get programmatically the ID of your lookup values based on your value at if condition below as the following

var LookupIdField = ListItem["LookupFieldName"] as FieldLookupValue[];

if (LookupIdField != null)
    foreach(var flookupID in LookupIdField)
        if (flookupID.LookupValue == "DataEntry Web 2.5")
           var FiledLoopkup_Id = flookupID.LookupId;

Regarding setting value for a single-value look up column you just need to set the column value ID to a FieldLookupValue instance, as mentioned at SharePoint client model and setting up lookup field

  • how does it know that var products relates to the "Products" list? Commented Sep 12, 2016 at 12:22
  • At which code you talk ? are you mean this var products = new[] { new FieldLookupValue { LookupId = 1 }, new FieldLookupValue { LookupId = 2} }; ? it's only array that you initalize it with the Lookup ID from Product List , please don't hesitate to ask me if you need more clarafication Commented Sep 12, 2016 at 12:26
  • Yes, that is the line I am referring to. Commented Sep 12, 2016 at 12:30
  • it's only array that you initalize it with the Lookup ID of items from Product List , Commented Sep 12, 2016 at 12:30
  • Thank you for the help. I got it to work! It must know the cast/type of the lookup field based on the field being assigned. The problem I was having was that I didn't realize I needed to do an update and execute for each lookup field. The entire record has 6 lookup fields and I was only doing 1 update/execute at the very end. Commented Sep 12, 2016 at 13:07

I have found similar question please refer it.
ID can then be used to set the listitem's FieldLookupValue.
Use below code to set your lookup field:

FieldLookupValue lv = new FieldLookupValue();
lv.LookupId = 1;
item["Project"] = lv;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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