更新TAXONOMY TERM STORE,托管元数据服务 [英] Update TAXONOMY TERM STORE, managed Metadata Service
问题描述
我正在构建分类学的托管元数据的树形视图.
我想建立一个描述为 的组,并通过按guid id搜索来指定为参数进行排序.
如果该组不存在,请创建它或通过guid获取grp并更新描述和排序.
然后,我想在上面创建/修改的该组下创建一个术语集,然后再次按guid搜索并修改描述和排序,然后最终在该术语集下创建/修改该术语并再次按guid搜索.
我想重新运行该脚本,因此,如果构建了术语集,只需用description和sort值覆盖它即可.
我不确定还是没有在网上看到代码,但不确定是否要删除网上论坛及其下的所有内容.
我希望在C#中做到这一点,并对此深表赞赏.
谢谢
I am in a process of building a tree view of managed meta data of taxonomy.
I want to build a group with a description and sort specified as parmeters by searching by guid id.
If the group is not there create it or get the grp by guid and update description and sort.
I then want to create a term set under that group above created/modified and again search by guid and modify the description and sort and then finally create/modify the term under that termset and again search by guid.
I want to re run the script so if term sets are built just override it with values of description and sort.
I am not sure or i havent seen the code on the net but i am not sure whether to delete the groups and everything under it.
I would like this in c# and really appreciated on this.
Thanks
推荐答案
您好,
此处是供您参考的代码段,您可以尝试使用它并发布详细问题(如果有).
https://msdn .microsoft.com/en-us/library/office/jj163949.aspx?f = 255& MSPPError = -2147217396
private void CreateColorsTermSet(string siteUrl)
{
ClientContext clientContext = new ClientContext(siteUrl);
TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
clientContext.Load(taxonomySession,
ts => ts.TermStores.Include(
store => store.Name,
store => store.Groups.Include(
group => group.Name
)
)
);
clientContext.ExecuteQuery();
if( taxonomySession != null )
{
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
if (termStore != null)
{
//
// Create group, termset, and terms.
//
TermGroup myGroup = termStore.CreateGroup("MyGroup",Guid.NewGuid());
TermSet myTermSet = myGroup.CreateTermSet("Color",Guid.NewGuid(), 1033);
myTermSet.CreateTerm("Red", 1033,Guid.NewGuid());
myTermSet.CreateTerm("Orange", 1033,Guid.NewGuid());
myTermSet.CreateTerm("Yellow", 1033,Guid.NewGuid());
myTermSet.CreateTerm("Green", 1033,Guid.NewGuid());
myTermSet.CreateTerm("Blue", 1033,Guid.NewGuid());
myTermSet.CreateTerm("Purple", 1033,Guid.NewGuid());
clientContext.ExecuteQuery();
}
}
}
private void DumpTaxonomyItems(string siteUrl)
{
ClientContext clientContext = new ClientContext(siteUrl);
//
// Load up the taxonomy item names.
//
TaxonomySession taxonomySession =TaxonomySession.GetTaxonomySession(clientContext);
TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
clientContext.Load(termStore,
store => store.Name,
store => store.Groups.Include(
group => group.Name,
group => group.TermSets.Include(
termSet => termSet.Name,
termSet => termSet.Terms.Include(
term => term.Name)
)
)
);
clientContext.ExecuteQuery();
//
//Writes the taxonomy item names.
//
if( taxonomySession != null )
{
if (termStore != null)
{
foreach( TermGroup groupin termStore.Groups)
{
Console.WriteLine("Group " + group.Name);
foreach( TermSet termSetin group.TermSets )
{
Console.WriteLine("TermSet " + termSet.Name);
foreach(Term term in termSet.Terms)
{
//Writes root-level terms only.
Console.WriteLine("Term " + term.Name);
}
}
}
}
}
}
最佳问候
Lee
这篇关于更新TAXONOMY TERM STORE,托管元数据服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!