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

2 Answers 2

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);
pfile.CheckOut();
ListItem li = File.ListItemAllFields;
li["Document_x0020_Type"] = "Personnel file";
li["Country0"] = "1;#China";
pfile.Update();
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;
oFile.ListItemAllFields.Update();
context.ExecuteQuery();
share|improve this answer

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.