2

We are downloading the Documents from a DocumentSet to a secondary fileRepository system which assigns them a UniqueID. I then need to update the DocumentSet Items with the new Unique ID per file. I'm using the below code which does not throw any errors but unfortunately, my Items are not being updated.

public static void UpdateNemswithRDIMSNumbers(ClientContext ctx, ListItem Item, List targetList, List<Business.Document> Documents)
    {
        foreach (Business.Document doc in Documents)
        {
            Web web = ctx.Web;
            ListCollection lists = web.Lists;
            var docLib = web.Lists.GetByTitle(SharePointConnector.DocumentLibrary);
            ctx.Load(docLib,
                               d => d.Title,
                               d => d.RootFolder.Name,
                               d => d.RootFolder.ServerRelativeUrl);
            ctx.Load(docLib);

            ctx.ExecuteQuery();

            ctx.Load(docLib);
            ctx.Load(docLib.RootFolder);
            ctx.Load(docLib.RootFolder.Folders);
            ctx.Load(docLib.RootFolder.Files);
            ctx.ExecuteQuery();
            FolderCollection fcol = docLib.RootFolder.Folders;

            string s = docLib.RootFolder.ServerRelativeUrl;

            foreach (Folder f in fcol)
            {
                //Find Parent Folder of the Current ITEM
                if ((f.Name).ToLower() == (Item["FileLeafRef"]).ToString().ToLower())
                {
                    ctx.Load(f.Files,
                                     items => items.Include(
                                                            item => item.ListItemAllFields));
                    ctx.ExecuteQuery();
                    FileCollection fileCol = f.Files;
                    foreach (Microsoft.SharePoint.Client.File file in fileCol)
                    {
                        if (doc.Description == (file.ListItemAllFields.FieldValues["FileLeafRef"]).ToString())
                        {
                            file.ListItemAllFields.FieldValues["NDMP_RDIMSDocumentID"] = doc.RDIMSNumber; //<-- The Update to be Made
                            file.ListItemAllFields.Update();
                        }                            
                    }
                    ctx.ExecuteQuery();
                }
            }
        }        
    }

1 Answer 1

0

You have a typo on the line below, i.e. "Filez"

List<Document.WithMetaData> filez = new List<Document.WithMetaData>();
1
  • Unfortunately, that's just a leftover from a prior version of the code, I've updated my exmample Jun 6, 2016 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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