SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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!

share|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
        {
            get
            {
                //return it here`enter code here`
            }
            set
            {
                //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;
share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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