Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've been able to create doc sets and upload files to it with the client object model. I am having difficulty updating the properties of the files in the doc sets. Here is what I've tried:

    public void UploadDocument(string siteurl, string listname, string docsetname, Microsoft.SharePoint.Client.File filename, string destination)
        {

            using (ClientContext clientContext = new ClientContext(siteurl))
            {
                clientContext.Credentials = new NetworkCredential("username", "password", "domain"); 
                //Get Document List
                List documentsList = clientContext.Web.Lists.GetByTitle(HttpUtility.UrlDecode(listname));

                clientContext.Load(filename);
                clientContext.ExecuteQuery();

                var xfile = destination + filename.Name;

                #region
                //filename.CopyTo(xfile, true);
                //clientContext.ExecuteQuery();

                //Microsoft.SharePoint.Client.FileInformation fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, filename.ServerRelativeUrl);
                //Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, destination, fileInformation.Stream, true);
                #endregion

                Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, xfile, 
                    Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, filename.ServerRelativeUrl).Stream, true);


//==============>this is my problem area <====================

                List oList = clientContext.Web.Lists.GetByTitle("Personnel Files2");

                CamlQuery cq = CamlQuery.CreateAllItemsQuery();
                ListItemCollection personFilesL =  oList.GetItems(cq);

                clientContext.Load(oList);
                clientContext.Load(personFilesL);
                clientContext.ExecuteQuery();

                var liItem = personFilesL.ToList().Select(c => c.FieldValues["Name"] == filename.Name); //.Where(c => c.FieldValues["Name"] == filename.Name).Select(c => c.FieldValues["id"]);
                ListItem li = oList.GetItems(liItem); //.GetItemById(liItem);

                li["Document_x0020_Type"] = "Personnel file";
                li["Country0"] = "1;#China";
                li.Update();


//=================> end problem area <=======================
                clientContext.ExecuteQuery();

            }
        }

What is the best way to update the properties of the files?

share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.