NavigationTermSetItem.GetAsEditable method
Returns an editable version of this NavigationTerm object or NavigationTermSet object.
Namespace: Microsoft.SharePoint.Publishing.Navigation
Assembly: Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)
Syntax
'Declaration
Public Function GetAsEditable ( _
taxonomySession As TaxonomySession _
) As NavigationTermSetItem
'Usage
Dim instance As NavigationTermSetItem
Dim taxonomySession As TaxonomySession
Dim returnValue As NavigationTermSetItem
returnValue = instance.GetAsEditable(taxonomySession)
public NavigationTermSetItem GetAsEditable(
TaxonomySession taxonomySession
)
Parameters
taxonomySession
Type: Microsoft.SharePoint.Taxonomy.TaxonomySessionThe TaxonomySession object for which to get a Term or TermSet object as editable.
Return value
Type: Microsoft.SharePoint.Publishing.Navigation.NavigationTermSetItem
An editable version of the NavigationTerm object or an editable version of the NavigationTermSet object
Remarks
The NavigationTerm and NavigationTermSet objects have two modes that reflect the most common usage patterns. In the “editable” mode, the object acts as a wrapper for the underlying analogous object in the N:Microsoft.SharePoint.Taxonomy namespace, and the object can be freely modified. In the “read-only” mode, the object uses a limited lightweight representation that does not reference objects from a TaxonomySession object. The “read-only” mode enables efficient storage in the taxonomy navigation cache and supports some traversal optimizations that improve performance when these optimizations are used with the TaxonomySiteMapProvider object. The “read-only” mode is set by the IsReadOnly property.
The GetAsEditable(TaxonomySession) method is used when the IsReadOnly() property equals true. It returns an editable version of this NavigationTerm object or NavigationTermSet object, which acts as a wrapper for the underlying Term or TermSet object from the TaxonomySession object that is provided.
Use the GetAsEditable when IsReadOnly=true.
Examples
This example shows how to use the GetAsEditable method to add a new link to a NavigationTermSet object that was retrieved from the cache.
static void CreateSimpleLink(SPWeb web)
{
// Retrieve the active NavigationTermSet object from the taxonomy navigation cache.
NavigationTermSet readOnlyTermSet = TaxonomyNavigation.GetTermSetForWeb(web,
"GlobalNavigationTaxonomyProvider", includeInheritedSettings: false);
// This operation would fail because readOnlyTermSet.IsReadOnly=true:
//readOnlyTermSet.CreateTerm("Search The Web", NavigationLinkType.SimpleLink);
// Get an editable version of the object.
TaxonomySession taxonomySession = new TaxonomySession(web, updateCache: true);
NavigationTermSet editableTermSet = readOnlyTermSet.GetAsEditable(taxonomySession);
// Configure the Taxonomy working language.
TermStore termStore = editableTermSet.GetTaxonomyTermStore();
termStore.WorkingLanguage = TaxonomyNavigation.GetNavigationLcidForWeb(web);
// Create the link by using the editable version of the object.
NavigationTerm editableTerm = editableTermSet.CreateTerm("Search The Web", NavigationLinkType.SimpleLink);
editableTerm.TargetUrl.Value = "https://www.bing.com/";
// Commit the changes to the taxonomy service.
termStore.CommitAll();
// Cause the cache to be updated immediately. Without this, it may
// take 5-10 seconds before this change is reflected in subsequent
// calls to GetTermSetForWeb().
TaxonomyNavigation.FlushTermSetFromCache(web, editableTermSet);
}
See also
Reference
Microsoft.SharePoint.Publishing.Navigation namespace