以编程方式创建术语集和术语 [英] Creating Termset and Terms Programmatically

查看:102
本文介绍了以编程方式创建术语集和术语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有两个问题



问题1:



如果termstore中不存在,我正在尝试创建一个termset。以下是我的代码



使用(SPSite mySite =新SPSite(URL))

{

uisng( SPWEb myWeb = mySite.OpenWeb())

{

TaxonomySession session = new TaxonomySession(myWeb.Site);

TermStore termStore = session。 TermStores [TermStoreName];

Group group = termStore.Groups(testGroupName);

var termSet = group.TermSets [testTermSet];

if(termset == null)



{

//代码制作

}

}

}



但它会在以下行引发错误

var termSet = group.TermSets [testTermSet];



那么如何检查TermSet是否存在,然后我们可以创建一个新的。



我的第二个问题是



我试图在现有的术语集中创建术语。以下是我的代码



如果在termstore中不存在,我正在尝试创建一个termset。以下是我的代码



使用(SPSite mySite =新SPSite(URL))

{

uisng( SPWEb myWeb = mySite.OpenWeb())

{

TaxonomySession session = new TaxonomySession(myWeb.Site);

TermStore termStore = session。 TermStores [TermStoreName];

Group group = termStore.Groups(testGroupName);

var termSet = group.TermSets [existingTermSet];

TermSet ts = null;

if(termset == null)



{

//代码创建

}

ts = group.TermSets [existingTermSet];

int lcid = CultureInfo.CurrentCulture.LCID;

ts.CreateTerm(ABC,lcid);

}

}



这会在以下行中抛出错误Value not not null:

ts.CreateTerm(ABC,lcid);



我对这两个错误感到很困惑,尤其是第二个错误。



请建议我一个替代或根本原因,以便我可以继续。我现在处于亏损状态。

Hi All,
I have two questions

Question 1:

I am trying to create a termset if it doesn't exist in termstore. Following is my code

using (SPSite mySite=new SPSite(URL))
{
uisng (SPWEb myWeb= mySite.OpenWeb())
{
TaxonomySession session = new TaxonomySession(myWeb.Site);
TermStore termStore = session.TermStores[TermStoreName];
Group group = termStore.Groups("testGroupName");
var termSet = group.TermSets["testTermSet"];
if (termset ==null)

{
//Code To Create
}
}
}

but it throws an error on the following line
var termSet = group.TermSets["testTermSet"];

So how can I check if a TermSet exist first, then we can create a new one.

My second question is

I am trying to create term inside an existing termset. Following is my code

I am trying to create a termset if it doesn't exist in termstore. Following is my code

using (SPSite mySite=new SPSite(URL))
{
uisng (SPWEb myWeb= mySite.OpenWeb())
{
TaxonomySession session = new TaxonomySession(myWeb.Site);
TermStore termStore = session.TermStores[TermStoreName];
Group group = termStore.Groups("testGroupName");
var termSet = group.TermSets["existingTermSet"];
TermSet ts=null;
if (termset ==null)

{
//Code To Create
}
ts=group.TermSets["existingTermSet"];
int lcid = CultureInfo.CurrentCulture.LCID;
ts.CreateTerm("ABC",lcid);
}
}

This throws an error saying "Value cannot be null" in the following line:
ts.CreateTerm("ABC",lcid);

I am really puzzled by these two errors, specially the second one.

Please suggest me an alternative or root cause so that I can proceed. I am at a loss right now.

推荐答案

对这些问题的任何答案?请...
Any Answers to these??Please...


这篇关于以编程方式创建术语集和术语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆