0

How to update columns inside a folder in sharepoint library using CSOM. I have a Document library in which I create folders programatically and copy files from another library into the created folder.I want to update the columns against each copied file inside the folder using C# in console application.

I am using

Folder folder = destList.RootFolder;
FolderCollection listfold = destList.RootFolder.Folders;
List<string> folders = new List<string>();
ctx.Load(listfold);
ctx.Load(folder);
ctx.Load(destList.RootFolder.Files);
ctx.ExecuteQuery();
foreach (Folder f in listfold)
{
  if (f.Name == prevMonth)
   {
     ctx.Load(f.Files);
     ctx.ExecuteQuery();
     FileCollection fcoll = f.Files;
     foreach (File file in fcoll)
      {
        //here InvoiceNo is name of my column inside document set in 
       //destination library. doc["InvoiceNo"] is item from source library 
       //from where file is being copied.

   file.Properties.FieldValues.Add("InvoiceNo",doc["InvoiceNo"].ToString());                                      
 }

kindly help me on how to update column values inside a document folder in a sharepoint library.

0

You're almost there ;). To update values of sharepoint column you need to pass by an ListItem
You can find this object with the property : ListItemAllFields of your SharePoint File.

You can try something like in your code :

foreach (File file in fcoll)
{
   //Load the SP ListITem of the File
   var item = file.ListItemAllFields;
   ctx.Load(item);
   ctx.ExecuteQuery();// Not sure if this is needed

   //Update value of the ListItem
   item["InvoiceNo"] = doc["InvoiceNo"].ToString();
   item.Update();
   //Save to SharePoint
   ctx.ExecuteQuery();
}

Hope this will help you

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.