Sunday, April 24, 2016

How to retrieve Location based metadata defaults using CSOM ?


Location based metadata defaults is a great feature to manage default values for documents in SharePoint Document Library. It allows to configure default values for document library, folders, sub folders etc. based on location / hierarchy so users will not have to provide the metadata values when they upload the documents in the document library.

To retrieve metadata defaults values programmatically, you will have to use Full trust object model because metadata defaults objects however are only available in Full trust object model. There is no REST API or Client Side Object Model (CSOM) API has been exposed to retrieve metadata defaults from SharePoint.

But we found the way of how SharePoint manages metadata defaults functionality, so we can retrieve metadata default in some clever way.

SharePoint stores metadata defaults in some html file (client_LocationBasedDefaults.html) in Document library itself. This file (client_LocationBasedDefaults.html) is stored in Forms folder of Document Library. You can find it out in SharePoint designer.





This file saves data in XML format with location / hierarchy (URL mapped with library, folder, sub folder etc.), Fields internal names and their default values as per configuration.




So you can just download this file using your C# code and read the content of this. So this way now you have all metadata defaults values available in your CSOM application. Enjoy!!

No comments:

Post a Comment