Provision property bag for document library declaratively via sandbox
-
07-10-2020 - |
Domanda
I have a no-code sandbox solution that I use to provision artefacts. One is a document library to which I want to attach a property bag to be set by a user via custom setting page.
I learned that one can not directly attach a property bag to a document library but only to its root folder. I know how to add property bags to items but did not succeed in adding those to a root folder.
Any help appreciated.
Soluzione
I got an answer from Margriet Bruggeman over at msdn: its not possible to declaratively add a property bag to the root folder. However it is via CSOM.
Solution: I - in any case - need a custom list settings link with attached configuration page to set/modify the property bag (via JSOM). Now I will use this very page to first check if there is a property bag and if not I'll simply create it.
Altri suggerimenti
You can update the property bag of the root folder of the document library using this code snippet.
//Load the document library and the root folder objects
ctx.Load(oDocLib);
ctx.Load(oDocLib.RootFolder);
ctx.ExecuteQuery();
// Create/update the root folder properties
oDocLib.RootFolder.Properties["Your_Custom_Property"] = "true"; // this is the same command to create and update a propety in the property bag
oDocLib.RootFolder.Update();
oDocLib.Update();
ctx.ExecuteQuery()
The same can be done using javascript also.