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'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));


                var xfile = destination + filename.Name;

                //filename.CopyTo(xfile, true);

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

                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);


                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";

//=================> end problem area <=======================


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

share|improve this question

A search for the same answr brought me to your (old) question. I found the answer and thought i'd share it with you. I code in VB.NET and i converted my code to your C# syntax. Replace your problem area with this code. That should probably do the trick.

File pfile = clientContext.Web.GetFileByServerRelativeUrl(xfile);
ListItem li = File.ListItemAllFields;
li["Document_x0020_Type"] = "Personnel file";
li["Country0"] = "1;#China";
pfile.CheckIn("", CheckinType.OverwriteCheckIn);
share|improve this answer

You can try this few lines of code.

// Update the Metadata for the uploaded file in to the Document Set
Microsoft.SharePoint.Client.File oFile =  oRootWeb.GetFileByServerRelativeUrl("Server relative url of the file");
oFile.ListItemAllFields["Migrated"] = true; 
oFile.ListItemAllFields["Author"] = sSystemAccount;
oFile.ListItemAllFields["Editor"] = sSystemAccount;
oFile.ListItemAllFields["Created"] = oAttachment.DateModified;
oFile.ListItemAllFields["Modified"] = oAttachment.DateModified;
share|improve this answer

Your Answer


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.