Property bag - Index using CSOM
-
18-01-2021 - |
Question
How can we check if the property bag is indexed and searchable?
And also how is the index value for 'vti_indexedpropertykeys' encoded?
I am trying to update the property bag's index using CSOM C# in .NET.So wanted to know how to verify it and know in what format the values are stored?
I found a AddIndexedPropertyBagKey property but do not know what value to set it with and what does it do.
Web web = clientContext.Site.RootWeb;
clientContext.Load(web, w => w.AllProperties);
clientContext.Load(web, w => w.Description);
clientContext.Load(web, w => w.Title);
clientContext.ExecuteQuery();
var allProperties = web.AllProperties;
web.AddIndexedPropertyBagKey = ??
Solution
I would suggest that you use the PnP Core Nuget package in your project.
It is a wrapper over the Native CSOM C# and provides a lot of extensions.
Using that, you can easily set the property bag value as well as mark it as indexed.
Use the below code:
Web web = clientContext.Site.RootWeb;
clientContext.Web.SetPropertyBagValue("key", "value");
clientContext.Web.AddIndexedPropertyBagKey("key");
To get the IndexedProperty
bag you can fetch the list of indexed property bags. If your property bag is marked as indexed, it will be available in the list:
var indexedPropertyBags = clientContext.Web.GetIndexedPropertyBagKeys();
Nuget Package - SharePointPnPCoreOnline