Several reasons of why TaxonomySession.DefaultKeywordsTermStore and DefaultSiteCollectionTermStore c



   When you work with Sharepoint managed metadata via object model you often need to write the code similar to the following:

   1: using(var site = new SPSite(url))
   2: {
   3:     var session = new TaxonomySession(site);
   4:     var termStore = session.DefaultKeywordsTermStore;
   5:     ...
   6: }

Sometimes TaxonomySession.DefaultKeywordsTermStore property may return null, i.e. termstore variable on line 4 in the example above will be null. In this case you can’t do any operations with managed metadata programmatically. What are the reasons of this behavior and how to fix it?

First of all check that your web application has connection with managed metadata service in Central administration > Manage web applications > Service connections:

image

This connection may be part of default connections set as shown on the picture above or included into the custom set. It is important that it will have only one connection, on one of the projects we encountered with situation when TaxonomySession.DefaultKeywordsTermStore returned null when there were several managed metadata connections defined for single web application.

If connection is defined properly go to Manage service applications > select Managed metadata service connection and click Properties button on the ribbon. On the opened dialog ensure that option “This service application is the default storage location for Keywords”:

image

There is also another option “This service application is the default storage location for column specific term sets”, but it affects another property: TaxonomySession.DefaultSiteCollectionTermStore .

If this step also didn’t help, check permissions. Go to Manage service applications > select Managed metadata service application and click Permissions button on the ribbon:

image

Ensure that account under which you run the code has at least “Read access to term store” right.

In most cases described steps should fix problem with null TaxonomySession.DefaultKeywordsTermStore or TaxonomySession.DefaultSiteCollectionTermStore properties. If you found some other reasons which can cause this problem, please share them in comments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值