SharePoint online Multilingual support - Development(2)
博客地址: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)的更多相关文章
- SharePoint online Multilingual support - Development(1)
博客地址:http://blog.csdn.net/FoxDave 上一节讲了SharePoint Online网站多语言的实现原理机制,本节主要从编程的角度来谈一下如何进行相关的设置. 下面列出 ...
- SharePoint online Multilingual support - Settings
博客地址:http://blog.csdn.net/FoxDave This post will talk about how to enable sharepoint online site mul ...
- Multi-lingual Support
Multi-lingual Support One problem with dealing with non-Latin characters programmatically is that, f ...
- SharePoint Security and Permission System Overview
转:http://www.sharepointblues.com/2010/09/01/sharepoint-security-and-permission-system-overview/ Shar ...
- 10 Skills Every SharePoint Developer Needs
10 Skills Every SharePoint Developer Needs(原文) This blog post guides you through the essential skill ...
- SharePoint 2013 搜索功能,列表项目不能完全被索引
描述 最近一个站点,需要开启搜索功能,然后创建内容源,开始爬网,发现列表里只有一部分被索引,很多项目没有被索引,甚是奇怪,如下图(其实列表里有80几条项目). 首先爬网账号是系统账号.服务器管理员,所 ...
- Device Channels in SharePoint 2013
[FROM:http://blog.mastykarz.nl/device-channels-sharepoint-2013/] One of the new features of SharePoi ...
- INCOIN Importing Multilingual Items (Doc ID 278126.1)
APPLIES TO: Oracle Inventory Management - Version: 11.5.9 to 11.5.10.CU2 - Release: 11.5 to 11.5 GOA ...
- [IT学习]微软如何做网站内容治理
How Microsoft does SharePoint Governance for their internal platform english sources from:http://www ...
随机推荐
- p1473 Zero Sum
搜索,最后判断一下是否结果为0就行. #include <iostream> #include <cstdio> #include <cmath> #include ...
- p1459 Sorting a Three-Valued Sequence
如果将1和3都放到正确的位置,2自然也在正确的位置.那么统计1,2,3的数量num1,num2,num3.再看前num1个数有几个(设x个)不是1,那么x个1肯定要移.设前num1个数有y个3,最后n ...
- linux中用composer安装yii框架
我的服务器是安装的是lanmp环境 如果环境版本比较低的话,建议升级一下版本 升级版本命令:./lanmp.sh cus 全都选择最高的.完成之后: curl -sS https://getcompo ...
- Northcott Game HDU - 1730
Tom和Jerry正在玩一种Northcott游戏,可是Tom老是输,因此他怀疑这个游戏是不是有某种必胜策略,郁闷的Tom现在向你求救了,你能帮帮他么? 游戏规则是这样的: 如图所示,游戏在一个n行m ...
- Music in Car CodeForces - 746F (贪心,模拟)
大意: n首歌, 第$i$首歌时间$t_i$, 播放完获得贡献$a_i$, 最多播放k分钟, 可以任选一首歌开始按顺序播放, 最多选w首歌半曲播放(花费时间上取整), 求贡献最大值. 挺简单的一个题, ...
- 并查集 牛客练习赛41 C抓捕盗窃犯
题目链接 :https://ac.nowcoder.com/acm/contest/373/C 题意,初始每一个城市都有一伙盗贼,没过一个时刻盗贼就会逃窜到另一个城市,你可以在m个城市设置监察站,会逮 ...
- XXX系统利益相关者分析
小组成员:白悦,张雪薇,李慧,陶雨洁 目标:实现需求的网上填报,征集. 好处: 1.便于统计 2.节约时间,成本 3.快捷简单易操作 度量标准:填报所用时间,精力,以及需求数据整理的有效性. 利益相关 ...
- vmplayer桥接以及nat配置nginx
1.环境 centos6.4 vm player nginx1.8 2.虚拟机的防火墙 参考http://blog.csdn.net/qilovehua/article/details/4550713 ...
- python中生成器
1.简介 通过列表生成式,我们可以直接创建一个列表,但是受到内存的限制,列表容量肯定是有限的. 如果列表元素可以按照某种算法推算出来,那我们是否可以在循环的过程中不断推算出后续的元素呢? 在Pytho ...
- [LightOJ 1265] Island of Survival
Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...