In one of my previous posts I showed how to provision managed metadata fields via sandbox solution and how to fix issues related with it: see Fix managed metadata fields after updating sandbox solution using client object model in Sharepoint. In this post I will show how to provision them via client object model. This method also can be used in Sharepoint Online and doesn’t require installations of any wsps.
First of all we need to declare taxonomy field itself and related note field:
The following properties are most important:
- SspId – term store id. You may get it in Site settings > Term store management and select top level node in the left tree view;
- TermSetID – id of term set which current field will be bound to. You may also get it from Site settings > Term store management;
- TextField – should contain id of related note field (declared above).
Having this xml definition we may create fields using the following client object model code:
After that field will be available in site columns.