Skip to content

Commit d4fd7cb

Browse files
Merge pull request SharePoint#6950 from PiotrekKrakowiak/patch-13
Add info about how to create Taxonomy fields programmatically (SSOM a…
2 parents 4e419dd + 9e678be commit d4fd7cb

File tree

1 file changed

+84
-182
lines changed

1 file changed

+84
-182
lines changed
Lines changed: 84 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,246 +1,148 @@
11
---
22
title: Managed metadata and navigation in SharePoint
33
description: Learn about enterprise managed metadata (EMM) and navigation features in SharePoint.
4-
ms.date: 03/23/2021
4+
ms.date: 05/18/2021
55
ms.prod: sharepoint
66
ms.assetid: b66d4ec1-a2ef-49cc-8ca5-a6b516bff02e
77
localization_priority: Normal
88
---
9-
10-
119
# Managed metadata and navigation in SharePoint
1210

13-
14-
15-
1611
![Conceptual overview topic](../images/mod_icon_badge_conoverview.png)
17-
18-
19-
2012

21-
22-
23-
24-
25-
26-
27-
2813
Learn about enterprise managed metadata (EMM) and navigation features in SharePoint.
14+
2915
## Managed metadata feature enhancements in SharePoint for developers
30-
<a name="SP15_ManagedMetadataAndNav_ManagedMetadataFeatureEnhancements"> </a>
3116

3217
You can use managed metadata to build taxonomies and tagging strategies that meet specific, detailed business needs. In SharePoint, the basic managed metadata API set is expanded and enhanced to provide more capabilities and scenario support.
33-
34-
35-
3618

3719
## .NET client object model (CSOM) support for managed metadata APIs
38-
<a name="SP15_ManagedMetadataAndNav_CSOMSupport"> </a>
3920

4021
The SharePoint CSOM supports taxonomy customization and development. Taxonomy is available in .NET client (CSOM), Silverlight, and JavaScript programming models. Developing with it is logically similar to developing with the .NET server programming model. You may find it useful to develop CSOM solutions to support scenarios where reading content is more common than authoring or administering it. You need to use CSOM to enable taxonomy use in a cloud scenario like SharePoint Online or for a subset of scenarios that are available on premises.
41-
42-
43-
22+
4423
When you want to create a new CSOM project in Visual Studio that uses taxonomy functionality, set the following references:
45-
46-
47-
4824

4925
- Microsoft.SharePoint.Client.dll
50-
51-
5226
- Microsoft.SharePoint.Client.Runtime.dll
53-
54-
5527
- Microsoft.SharePoint.Client.Taxonomy.dll
56-
57-
28+
5829
Developing customizations with CSOM is very similar to developing .NET server taxonomy solutions: get a reference to the **TaxonomySession** object and the **TermStore** object, **Group** objects, **TermSet** objects, and **Term** objects required for the session.
59-
60-
61-
6230

6331
### Code Examples: Basic operations with the Taxonomy CSOM
64-
<a name="SP15_ManagedMetadataAndNav_ExampleBasicOperations"> </a>
6532

6633
You can use the following code examples to complete basic operations with the taxonomy CSOM. The first example creates a **Group** object, a **TermSet** object, and **Term** objects. The second example iterates on a **Group** object and writes its contents.
67-
68-
69-
7034

7135
```cs
72-
73-
private void CreateColorsTermSet(string siteUrl)
74-
{
75-
ClientContext clientContext = new ClientContext(siteUrl);
76-
77-
TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
78-
clientContext.Load(taxonomySession,
79-
ts => ts.TermStores.Include(
80-
store => store.Name,
81-
store => store.Groups.Include(
82-
group => group.Name
83-
)
84-
)
85-
);
86-
clientContext.ExecuteQuery();
87-
88-
if( taxonomySession != null )
89-
{
90-
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
91-
if (termStore != null)
92-
{
93-
//
94-
// Create group, termset, and terms.
95-
//
96-
TermGroup myGroup = termStore.CreateGroup("MyGroup",Guid.NewGuid());
97-
TermSet myTermSet = myGroup.CreateTermSet("Color",Guid.NewGuid(), 1033);
98-
myTermSet.CreateTerm("Red", 1033,Guid.NewGuid());
99-
myTermSet.CreateTerm("Orange", 1033,Guid.NewGuid());
100-
myTermSet.CreateTerm("Yellow", 1033,Guid.NewGuid());
101-
myTermSet.CreateTerm("Green", 1033,Guid.NewGuid());
102-
myTermSet.CreateTerm("Blue", 1033,Guid.NewGuid());
103-
myTermSet.CreateTerm("Purple", 1033,Guid.NewGuid());
104-
105-
clientContext.ExecuteQuery();
106-
}
107-
}
108-
}
109-
110-
private void DumpTaxonomyItems(string siteUrl)
111-
{
112-
ClientContext clientContext = new ClientContext(siteUrl);
113-
114-
//
115-
// Load up the taxonomy item names.
116-
//
117-
TaxonomySession taxonomySession =TaxonomySession.GetTaxonomySession(clientContext);
118-
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
119-
clientContext.Load(termStore,
120-
store => store.Name,
121-
store => store.Groups.Include(
122-
group => group.Name,
123-
group => group.TermSets.Include(
124-
termSet => termSet.Name,
125-
termSet => termSet.Terms.Include(
126-
term => term.Name)
127-
)
128-
)
129-
);
130-
clientContext.ExecuteQuery();
131-
132-
133-
//
134-
//Writes the taxonomy item names.
135-
//
136-
if( taxonomySession != null )
137-
{
138-
if (termStore != null)
139-
{
140-
foreach(TermGroup group in termStore.Groups)
141-
{
142-
Console.WriteLine("Group " + group.Name);
143-
144-
foreach(TermSet termSet in group.TermSets )
145-
{
146-
Console.WriteLine("TermSet " + termSet.Name);
147-
148-
foreach(Term term in termSet.Terms)
149-
{
150-
//Writes root-level terms only.
151-
Console.WriteLine("Term " + term.Name);
152-
}
153-
}
154-
}
155-
}
156-
}
157-
36+
private void CreateColorsTermSet(string siteUrl)
37+
{
38+
ClientContext clientContext = new ClientContext(siteUrl);
39+
40+
TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
41+
clientContext.Load(taxonomySession,
42+
ts => ts.TermStores.Include(
43+
store => store.Name,
44+
store => store.Groups.Include(group => group.Name)
45+
)
46+
);
47+
clientContext.ExecuteQuery();
48+
49+
if( taxonomySession != null ) {
50+
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
51+
if (termStore != null) {
52+
//
53+
// Create group, termset, and terms.
54+
//
55+
TermGroup myGroup = termStore.CreateGroup("MyGroup",Guid.NewGuid());
56+
TermSet myTermSet = myGroup.CreateTermSet("Color",Guid.NewGuid(), 1033);
57+
myTermSet.CreateTerm("Red", 1033,Guid.NewGuid());
58+
myTermSet.CreateTerm("Orange", 1033,Guid.NewGuid());
59+
myTermSet.CreateTerm("Yellow", 1033,Guid.NewGuid());
60+
myTermSet.CreateTerm("Green", 1033,Guid.NewGuid());
61+
myTermSet.CreateTerm("Blue", 1033,Guid.NewGuid());
62+
myTermSet.CreateTerm("Purple", 1033,Guid.NewGuid());
63+
64+
clientContext.ExecuteQuery();
65+
}
66+
}
67+
}
68+
69+
private void DumpTaxonomyItems(string siteUrl)
70+
{
71+
ClientContext clientContext = new ClientContext(siteUrl);
72+
73+
//
74+
// Load up the taxonomy item names.
75+
//
76+
TaxonomySession taxonomySession =TaxonomySession.GetTaxonomySession(clientContext);
77+
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
78+
clientContext.Load(termStore,
79+
store => store.Name,
80+
store => store.Groups.Include(
81+
group => group.Name,
82+
group => group.TermSets.Include(
83+
termSet => termSet.Name,
84+
termSet => termSet.Terms.Include(
85+
term => term.Name)
86+
)
87+
)
88+
);
89+
clientContext.ExecuteQuery();
90+
91+
92+
//
93+
//Writes the taxonomy item names.
94+
//
95+
if( taxonomySession != null ) {
96+
if (termStore != null) {
97+
foreach(TermGroup group in termStore.Groups) {
98+
Console.WriteLine("Group " + group.Name);
99+
foreach(TermSet termSet in group.TermSets ) {
100+
Console.WriteLine("TermSet " + termSet.Name);
101+
foreach(Term term in termSet.Terms) {
102+
//Writes root-level terms only.
103+
Console.WriteLine("Term " + term.Name);
104+
}
158105
}
159-
106+
}
107+
}
108+
}
109+
}
160110
```
161111

162-
163-
164-
165-
166-
167112
## Pinning
168-
<a name="SP15_ManagedMetadataAndNav_Pinning"> </a>
169113

170114
In Microsoft SharePoint Server 2010, users could reuse terms (and all terms nested under the reused terms) in other locations in the term hierarchy. After these terms were reused, they could be modified and changes would be seen everywhere the terms were reused. SharePoint introduces term pinning. A pinned term is just like a term that is reused, except it is read only and cannot be changed in the locations where the term is reused. For an example, see [How to: Use code to pin terms to navigation term sets in SharePoint](how-to-use-code-to-pin-terms-to-navigation-term-sets-in-sharepoint.md).
171-
172-
173-
174-
175-
176-
177-
178115

179116
## Datasheet view support for managed metadata column types
180-
<a name="SP15_ManagedMetadataAndNav_DatasheetViewSupport"> </a>
181117

182118
In SharePoint, the datasheet view functionality has changed. Now, the datasheet uses a double-click action to open standard view for grid editing. You can now edit metadata columns using the same features that are available when you edit individual items. This includes access to the term set that is behind the column. This feature is all about bringing the metadata modification functionality available when editing an individual item to datasheet editing.
183-
184-
185-
186119

187120
## Managed navigation
188-
<a name="SP15_ManagedMetadataAndNav_ManagedNav"> </a>
189121

190122
Managed navigation uses managed metadata features, such as the ability to tag items with terms and manage terms in a term store, to provide highly customized site navigation. The structured navigation that depends on the SharePoint infrastructure is also still available in SharePoint.
191-
192-
193-
194123

195124
## Friendly URLs
196-
<a name="SP15_ManagedMetadataAndNav_FriendlyURLs"> </a>
197125

198-
Friendly URLs are a shorter URL format displayed in the address bar of most SharePoint publishing pages, including the Welcome Page of your site. They are SEO-friendly and appear in search results.
199-
200-
201-
126+
Friendly URLs are a shorter URL format displayed in the address bar of most SharePoint publishing pages, including the Welcome Page of your site. They are SEO-friendly and appear in search results.
202127

203128
## Support for new scenarios
204-
<a name="SP15_ManagedMetadataAndNav_SupportForNewScenarios"> </a>
205129

206130
A term store manager can enhance and expand term usage models based on more flexible and powerful managed metadata functionality in :
207-
208-
209-
210131

211-
- Link to another site collection and view others' terms. If you want to make your term set available to other site collections connected to the managed metadata service, create a **global term set**. If you want to create a private term set that is available only to a specific site collection when it is stored in the managed metadata service, create a **local term set**.
212-
213-
132+
- Link to another site collection and view others' terms. If you want to make your term set available to other site collections connected to the managed metadata service, create a **global term set**. If you want to create a private term set that is available only to a specific site collection when it is stored in the managed metadata service, create a **local term set**.
214133
- Block users from using keywords outside of a specific term set.
215-
216-
217-
- Gain additional multilingual support, including support for automated translation and flexible LCIDs.
218-
219-
134+
- Gain additional multilingual support, including support for automated translation and flexible LCIDs.
135+
- For programmatic creation of taxonomy fields using the SharePoint Server Object Model, please refer to the sample: [TaxonomyField Class](/dotnet/api/microsoft.sharepoint.taxonomy.taxonomyfield)
136+
- For programmatic creation of taxonomy fields using the SharePoint Client Side Object Model (CSOM), you can use a similar pattern as above taking into consideration the following sample: [Complete basic operations using SharePoint client library code](../sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code.md#add-a-field-to-a-sharepoint-list)
220137

221138
## Unsupported scenarios for working with custom site definitions
222-
<a name="SP15_ManagedMetadataAndNav_UnsupportedScenarios"> </a>
223-
224139

225140
- SharePoint does not support creating taxonomy fields (managed metadata site columns) declaratively by way of XML definition.
226-
227-
228141
- SharePoint does not support the use of taxonomy fields (managed metadata site columns) in site templates.
229-
230-
231142
- For more information, see Microsoft Support Article #898631: [Supported and unsupported scenarios](https://support2.microsoft.com/default.aspx?scid=kb;EN-US;898631
232143
)
233-
234-
235144

236145
## See also
237-
<a name="SP15_ManagedMetadataAndNav_AdditionalResources"> </a>
238-
239-
240-
- [Managed navigation in SharePoint](managed-navigation-in-sharepoint.md)
241-
242-
243-
- [Content Search web part in SharePoint](content-search-web-part-in-sharepoint.md)
244-
245-
246146

147+
- [Managed navigation in SharePoint](managed-navigation-in-sharepoint.md)
148+
- [Content Search web part in SharePoint](content-search-web-part-in-sharepoint.md)

0 commit comments

Comments
 (0)