Property Bags
Property bags operations
Property bags are a nice way of storing global metadata and settings in SharePoint. Property bags are key-value pairs scoped to the container. In general, any folder can act as a container, also webs have their own property bag storage located in all properties section.
Use-cases can vary depending on how an application uses this key-value storage. For example, PnP Provisioning engine stores applied schema information in property bags. A good thing is that you don't need to provision any additional artifacts to keep some business logic or state variables.
A thing to know that all the props values are strings, dealing with different data types they should be serialized or converted to a string.
Getting web's all properties
Getting specific properties
To get a limited subset of properties .GetProps
helper method can be used:
Selecting specific properties didn't work in old versions of SharePoint, however, the method has a fallback to getting all and filtering props on the client.
Setting property value
Modern SharePoint sites by default have custom scripting disabled mode. When custom scripting is disabled even an admin account will receive "Access denied. You do not have permission to perform this action or access this resource." error message. This is the expected behavior.
Setting props require "Custom Script" be allowed on a site. See more.
We recommend Office 365 CLI to enable custom scripting.
Getting folder property bags
Setting many properties values
Summary
Property bags are a robust way of storing custom settings and state which requires no additional artifacts. When structuring and consuming correctly they can be a great addition to the application logic.
Last updated