- 12 May , 2016
- by Neeraj Agarwal
- 0 comments
- 1079 Views
The Document Library is a place on a Sharepoint site where you can create, collect, and update files with others. The library, though, can sometimes get cluttered and difficult to manage.
Location based metadata defaults is a great feature to manage default values for documents in sharepoint document Library. It allows you 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.
How to setup Metadata defaults in Document Library?
Following steps give you a very quick overview on how to configure the default column values feature in SharePoint. (These screenshots are for SharePoint 2013, but it’s almost identical in 2010 as well).
open Document Library -> Library Settings -> General Settings -> Column Default Value Settings
Here you can configure default values for several fields (fields those support metadata defaults) for different location/hierarchies.
If you don’t configure default values for any folder or sub-folder then it will be inheriting default values from its parent hierarchy otherwise its own configured default values.
Once you configured default values, go to your Document library or folder inside it and try adding any document, you will be having configured default values auto filled in those fields in Edit metadata form.
How to retrieve Location based metadata defaults using CSOM?
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.
I hope this article would help you out in making your Sharepoint experience better. If you had a good time reading, then subscribe to the blog and we will keep you updated with our technological musings.