SharePoint online Multilingual support - Development(2)

时间:2022-09-19 08:33:09

博客地址:http://blog.csdn.net/FoxDave

上一节讲了如何通过Code的方式设置Site和List级别的国际化,本节介绍一下如何设置Content type和Site column级别的国际化。废话不多说了,还是以代码的方式带大家go through这个过程。

Content type和Site column级别的国际化

跟之前一样,为了测试咱们先创建专用的Site column和Content type,需要把Site column添加到Content type,所以先创建一个Site column。

创建Site column的代码如下所示:

private static void CreateSiteColumn(ClientContext cc, Web web)
{
// Add site column to the content type if it's not there...
FieldCollection fields = web.Fields;
cc.Load(fields);
cc.ExecuteQuery(); foreach (var item in fields)
{
if (item.InternalName == "ContosoString")
return;
} string FieldAsXML = @"<Field ID='{4F34B2ED-9CFF-4900-B091-4C0033F89944}'
Name='ContosoString'
DisplayName='Contoso String'
Type='Text'
Hidden='False'
Group='Contoso Site Columns'
Description='Contoso Text Field' />";
Field fld = fields.AddFieldAsXml(FieldAsXML, true, AddFieldOptions.DefaultValue);
cc.Load(fields);
cc.Load(fld);
cc.ExecuteQuery();
}

上面的代码创建了一个名为ContosoString的Site column,并指定ID为4F34B2ED-9CFF-4900-B091-4C0033F89944。接下来咱们创建Content type,代码如下:

private static void CreateContentTypeIfDoesNotExist(ClientContext cc, Web web)
{
ContentTypeCollection contentTypes = web.ContentTypes;
cc.Load(contentTypes);
cc.ExecuteQuery(); foreach (var item in contentTypes)
{
if (item.StringId == "0x0101009189AB5D3D2647B580F011DA2F356FB2")
return;
} // Create a Content Type Information object
ContentTypeCreationInformation newCt = new ContentTypeCreationInformation();
// Set the name for the content type
newCt.Name = "Contoso Document";
//Inherit from oob document - 0x0101 and assign
newCt.Id = "0x0101009189AB5D3D2647B580F011DA2F356FB2";
// Set content type to be avaialble from specific group
newCt.Group = "Contoso Content Types";
// Create the content type
ContentType myContentType = contentTypes.Add(newCt);
cc.ExecuteQuery();
}

上面的代码创建了名为Consoto Document的Content type,指定了ID为0x0101009189AB5D3D2647B580F011DA2F356FB2。接下来咱们需要将新建的Site column添加到新建的Content type中,代码如下:

private static void AddSiteColumnToContentType(ClientContext cc, Web web)
{
ContentTypeCollection contentTypes = web.ContentTypes;
cc.Load(contentTypes);
cc.ExecuteQuery();
ContentType myContentType = contentTypes.GetById("0x0101009189AB5D3D2647B580F011DA2F356FB2");
cc.Load(myContentType);
cc.ExecuteQuery(); FieldCollection fields = web.Fields;
Field fld = fields.GetByInternalNameOrTitle("ContosoString");
cc.Load(fields);
cc.Load(fld);
cc.ExecuteQuery(); FieldLinkCollection refFields = myContentType.FieldLinks;
cc.Load(refFields);
cc.ExecuteQuery(); foreach (var item in refFields)
{
if (item.Name == "ContosoString")
return;
} // ref does nt
FieldLinkCreationInformation link = new FieldLinkCreationInformation();
link.Field = fld;
myContentType.FieldLinks.Add(link);
myContentType.Update(true);
cc.ExecuteQuery();
}

通过以上的代码,咱们用于测试的数据就创建完了,下面的代码就来演示如何设置国际化属性了:

private static void LocalizeContentTypeAndField(ClientContext cc, Web web)
{
ContentTypeCollection contentTypes = web.ContentTypes;
ContentType myContentType = contentTypes.GetById("0x0101009189AB5D3D2647B580F011DA2F356FB2");
cc.Load(contentTypes);
cc.Load(myContentType);
cc.ExecuteQuery();
// Title of the content type
myContentType.NameResource.SetValueForUICulture("en-US",
"Contoso Document");
myContentType.NameResource.SetValueForUICulture("fi-FI",
"Contoso Dokumentti");
myContentType.NameResource.SetValueForUICulture("fr-FR",
"Contoso Document (FR)");
// Description of the content type
myContentType.DescriptionResource.SetValueForUICulture("en-US",
"This is the Contoso Document.");
myContentType.DescriptionResource.SetValueForUICulture("fi-FI",
"Tämä on geneerinen Contoso dokumentti.");
myContentType.DescriptionResource.SetValueForUICulture("fr-FR",
"French Contoso document.");
myContentType.Update(true);
cc.ExecuteQuery(); // Do localization also for the site column
FieldCollection fields = web.Fields;
Field fld = fields.GetByInternalNameOrTitle("ContosoString");
fld.TitleResource.SetValueForUICulture("en-US", "Contoso String");
fld.TitleResource.SetValueForUICulture("fi-FI", "Contoso Teksti");
fld.TitleResource.SetValueForUICulture("fr-FR", "Contoso French String");
// Description entry
fld.DescriptionResource.SetValueForUICulture("en-US",
"Used to store Contoso specific metadata.");
fld.DescriptionResource.SetValueForUICulture("fi-FI",
"Tää on niiku Contoso metadatalle.");
fld.DescriptionResource.SetValueForUICulture("fr-FR",
"French Description Goes here");
fld.UpdateAndPushChanges(true);
cc.ExecuteQuery();
}

跟Site和List级别同理,就不做过多解释了。
原文地址:https://blogs.msdn.microsoft.com/vesku/2014/03/20/office365-multilingual-content-types-site-columns-and-other-site-elements/

SharePoint online Multilingual support - Development(2)的更多相关文章

  1. SharePoint online Multilingual support - Development&lpar;1&rpar;

    博客地址:http://blog.csdn.net/FoxDave 上一节讲了SharePoint Online网站多语言的实现原理机制,本节主要从编程的角度来谈一下如何进行相关的设置. 下面列出 ...

  2. SharePoint online Multilingual support - Settings

    博客地址:http://blog.csdn.net/FoxDave This post will talk about how to enable sharepoint online site mul ...

  3. Multi-lingual Support

    Multi-lingual Support One problem with dealing with non-Latin characters programmatically is that, f ...

  4. SharePoint Security and Permission System Overview

    转:http://www.sharepointblues.com/2010/09/01/sharepoint-security-and-permission-system-overview/ Shar ...

  5. 10 Skills Every SharePoint Developer Needs

    10 Skills Every SharePoint Developer Needs(原文) This blog post guides you through the essential skill ...

  6. SharePoint 2013 搜索功能,列表项目不能完全被索引

    描述 最近一个站点,需要开启搜索功能,然后创建内容源,开始爬网,发现列表里只有一部分被索引,很多项目没有被索引,甚是奇怪,如下图(其实列表里有80几条项目). 首先爬网账号是系统账号.服务器管理员,所 ...

  7. Device Channels in SharePoint 2013

    [FROM:http://blog.mastykarz.nl/device-channels-sharepoint-2013/] One of the new features of SharePoi ...

  8. INCOIN Importing Multilingual Items &lpar;Doc ID 278126&period;1&rpar;

    APPLIES TO: Oracle Inventory Management - Version: 11.5.9 to 11.5.10.CU2 - Release: 11.5 to 11.5 GOA ...

  9. &lbrack;IT学习&rsqb;微软如何做网站内容治理

    How Microsoft does SharePoint Governance for their internal platform english sources from:http://www ...

随机推荐

  1. 学记:spring boot使用官网推荐以外的其他数据源druid

    虽然spring boot提供了4种数据源的配置,但是如果要使用其他的数据源怎么办?例如,有人就是喜欢druid可以监控的强大功能,有些人项目的需要使用c3p0,那么,我们就没办法了吗?我们就要编程式 ...

  2. html5的本地存储

    转载1:http://www.cnblogs.com/fly_dragon/p/3946012.html 转载2:http://www.cnblogs.com/xiaowei0705/archive/ ...

  3. Apache搭建多个站点方法详解

    www.111cn.net 编辑:Bolshevik 来源:转载 Apache的虚拟主机是一种允许在同一台机器上配置多个不同站点的web服务器环境的,就是iis一样可以创建多站点了,但是apache需 ...

  4. 递归&colon;这帮坑爹的小兔崽子 - 零基础入门学习Python023

    递归:这帮坑爹的小兔崽子 让编程改变世界 Change the world by program 斐波那契数列的递归实现 这节课我们用斐波那契(Fibonacci)数列的递归实现来作为第一个例子吧,斐 ...

  5. 【算法导论】最小生成树之Prime法

    关于最小生成树的概念,在前一篇文章中已经讲到,就不在赘述了.下面介绍Prime算法:         其基本思想为:从一个顶点出发,选择由该顶点出发的最小权值边,并将该边的另一个顶点包含进来,然后找出 ...

  6. JS十种经典排序算法,纯动画演示,学会了怼死面试官!

    十种常见排序算法可以分为两大类: 非线性时间比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此称为非线性时间比较类排序. 线性时间非比较类排序:不通过比较来决定 ...

  7. Spring -- 自定义转换器

    Spring 定义了 3 种类型的转换器接口,实现任意一个转换器接口都可以作为自定义转换器注册到 ConversionServiceFactoryBean 中: Converter<S,T&gt ...

  8. rimraf node&lowbar;modules 快速删除

     npm install -g rimraf   // 先进行全局安装 rimraf node_modules   // 进行删除   -------------------------------- ...

  9. Python学习笔记第十一周

    目录: 1.RabbitMQ   2.Redis  内容: 1.RabbitMQ 实现简单的队列通信 send端 import pika credentials = pika.PlainCredent ...

  10. P1522 牛的旅行 Cow Tours

    题目描述 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不连通.这样,Farmer John就有多个 ...