创建taxonomy field之前我们首先来学习一下如果创建termSet,原因是我们所创建的taxonomy field需要关联到termSet。

简单介绍一下Taxonomy Term Store的层次结构:

TermStore

Group

TermSet

Term //Term可以继续创建Term

1、首先,我们需要new TaxonomySession对象,然后获取到TermStore

TaxonomySession session = new TaxonomySession(Site);//Site即为SPSite对象
TermStore termStore = session.TermStores[MetadataService];//MetadataService 即为SharePoint Managed Metadata Service name, 如果没有即需要创建一个Managed Metadata Service,具体如何创建这里不做介绍。

2、创建Group,创建Group之前我们需要check一下Group是否存在,我们可以简单的通过Linq语句来完成所需要的工作

Group group = termStore.Groups.Where(g => g.Name.Equals(groupName, StringComparison.OrdinalIgnoreCase)).Count() >  ?
termStore.Groups[groupName] : termStore.CreateGroup(groupName);

3、创建TermSet,创建TermSet的时候可以指定TermSet的Lcid,我们可以通过如下2中方式获取

int lcid = termStore.DefaultLanguage;//推荐
//or
int lcid = CultureInfo.CurrentCulture.LCID;//不推荐,原因是机器语言和SharePoint环境语言有可能不一致
TermSet rootTermSet = group.TermSets.Where(ts => ts.Name == termSetName).Count() >  ?
group.TermSets[termSetName] : group.CreateTermSet(termSetName, Guid.NewGuid(), lcid);

4、创建Term

 Term term = rootTermSet.Terms.Where(t => t.Name.Equals(termname, StringComparison.OrdinalIgnoreCase)).Count() >  ?
rootTermSet.Terms[termname] : rootTermSet.CreateTerm(termname, lcid, Guid.NewGuid());

5、commit

 termStore.CommitAll();

6、创建Taxonomy field

TaxonomyField taxonomyField = Site.RootWeb.Fields.CreateNewField("TaxonomyFieldType", "taxonomyFieldName") as TaxonomyField;
taxonomyField.Description = "This is test for cnblogs.";
taxonomyField.SspId = termStore.Id;
taxonomyField.TermSetId = rootTermSet.Id;//taxonomy field binding to termSet
taxonomyField.AllowMultipleValues = true;
taxonomyField.Group = "Custom Columns";//taxonmy field default site column group
Site.RootWeb.Fields.Add(taxonomyField);
Site.RootWeb.Update();

7、测试,获取taxonomy field

TaxonomyField field = site.RootWeb.Fields["taxonomyFieldName"] as TaxonomyField;

OK,you have been  created taxonomyField successfully。

SharePoint 2013 Create taxonomy field的更多相关文章

  1. SharePoint 2013 create workflow by SharePoint Designer 2013

    这篇文章主要基于上一篇http://www.cnblogs.com/qindy/p/6242714.html的基础上,create a sample workflow by SharePoint De ...

  2. SharePoint 2013 Create Folder with conententtype programer

    记录一下昨天写的SharePoint tool,需求是这样的: 在SharePoint list subfolder 下创建1000个folder,这些folder指定特殊的contenttype,c ...

  3. [SharePoint 2013] Create event receiver for external list

    Main list for creating event receiver for external list Subscribe   storage, it could be data table ...

  4. Working With Taxonomy Field in CSOM

    How to create taxonomy field with CSOM If you need to programmatic create a taxonomy field, you need ...

  5. 移动设备和SharePoint 2013 - 第3部分:推送通知

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...

  6. Create a “% Complete” Progress Bar with JS Link in SharePoint 2013

    Create a “% Complete” Progress Bar with JS Link in SharePoint 2013 SharePoint 2013 has a lot new fea ...

  7. SharePoint 2013 configure and publish infopth

    This article will simply descript how to configure and publish a InfoPath step by step. Note: To con ...

  8. Creating Custom Connector Sending Claims with SharePoint 2013

    from:http://blogs.msdn.com/b/security_trimming_in_sharepoint_2013/archive/2012/10/29/creating-custom ...

  9. 解决SharePoint 2013 designer workflow 在发布的报错“负载平衡没有设置”The workflow files were saved but cannot be run.

    原因是app management service没有设置好,在管理中心把他删掉,重新建一个就可以了 Provision App Management Service In SharePoint 20 ...

随机推荐

  1. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  2. JS核心系列:浅谈原型对象和原型链

    在Javascript中,万物皆对象,但对象也有区别,大致可以分为两类,即:普通对象(Object)和函数对象(Function). 一般而言,通过new Function产生的对象是函数对象,其他对 ...

  3. Java基础Map接口+Collections

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

  4. iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  5. linux服务器开发一 基础

    注:本文仅限交流使用,请务用于商业用途,否则后果自负! Linux 1.Linux介绍 Linux是类Unix计算机操作系统的统称. Linux操作系统的内核的名字也是“Linux”. Linux这个 ...

  6. java中if和switch哪个效率快

    首先要看一个问题,if 语句适用范围比较广,只要是 boolean 表达式都可以用 if 判断:而 switch 只能对基本类型进行数值比较.两者的可比性就仅限在两个基本类型比较的范围内.说到基本类型 ...

  7. 【干货分享】流程DEMO-离职流程

    流程名: 离职申请   流程相关文件: 流程包.xml WebService业务服务.xml WebService.asmx WebService.cs   流程说明: 流程中集成了webservic ...

  8. GIT笔记命令行(1)

    Git简单易用,只要输入git就可以列出他的所有参数 C:\Users\spu>git usage: git [--version] [--help] [-C <path>] [-c ...

  9. angular中使用ngResource模块构建RESTful架构

    ngResource模块是angular专门为RESTful架构而设计的一个模块,它提供了'$resource'模块,$resource模块是基于$http的一个封装.下面来看看它的详细用法 1.引入 ...

  10. 作为前端应当了解的Web缓存知识

    缓存优点 通常所说的Web缓存指的是可以自动保存常见http请求副本的http设备.对于前端开发者来说,浏览器充当了重要角色.除此外常见的还有各种各样的代理服务器也可以做缓存.当Web请求到达缓存时, ...