I have a CSOM console app that uploads files to a library, then it creates a lookup field in another list and also adds lookups to the files in my library.

The following code adds a single item in the lookup:

FieldLookupValue flv = new FieldLookupValue() { LookupId = Convert.ToInt32(attachmentFile.Id) };
listItem["MyAttachments"] = flv;

How can i modify this to add multiple FieldLookupValue's?


Try the following:

Create a List of FieldLookupValue's

List<FieldLookupValue> lookupValues = new List<FieldLookupValue>();

Add a new FieldLookupValue for each file id

lookupValues.Add(new FieldLookupValue() { LookupId = Convert.ToInt32(attachmentFile.Id) });

When finished set the listItem to the List

listItem["MyAttachments"] = lookupValues;

Hope this works for you!

|improve this answer|||||
  • Hi Tom, thanks so much for the assistance. That worked perfectly for me. So simple. Im embarassed i didnt see that solution myself. – Cobus de Witt Jun 26 '13 at 6:50

You can declare Property like below

public ICollection<FieldLookupValue> Brand { get; set; }

Below you can get set the Property :

ICollection<FieldLookupValue> ICustomerRequirementView.Brand
                //return it here`enter code here`
                //set it here
                //new List<FieldLookupValue> { new FieldLookupValue() { LookupId = 1 } }

//below u can set the value in ListItemCreationInformation object

ListItemCreationInformation listObj = new ListItemCreationInformation();
                ListItem item = ctx.Web.Lists.GetByTitle("CustomerRequirement").AddItem(listObj);
                item["Brand"] = customerRequirement.Brand;
|improve this answer|||||
  • Would you please explain your answer, How it can be used to solve the problem. It will be very useful for the readers. – Asad Refai Sep 22 '15 at 5:41

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.