SharePoint online Multilingual support
来源:互联网 发布:sql server 2008r2下载 编辑:程序博客网 时间:2024/06/05 02:12
博客地址: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/
1 0
- SharePoint online Multilingual support
- SharePoint online Multilingual support
- SharePoint online Multilingual support
- SharePoint online ClientContext
- SharePoint Online 创建图片库
- SharePoint Online 创建网站集
- SharePoint Online 设置网站集
- SharePoint Online 创建列表库
- SharePoint Online 创建文档库
- SharePoint Online 创建资产库
- Connecting SharePoint Online and CRM Online using BCS - 2013 Edition-SP online连接CRM online
- 微软云计算服务 - Microsoft SharePoint Online
- SharePoint Online 沙盒解决方案开发小结
- 申请免费的sharepoint online开发站点
- Sharepoint online 创建模板与使用模板
- Office365 sharepoint online 如何设置匿名访问
- sharepoint online JS 访问Azure web 项目
- SharePoint Online:软件边界和限制
- Keepalived + Nginx实现高可用 Web负载均衡
- 蓝桥杯2014年第五届决赛C_C++程序设计本科B组
- 画PCB技巧及快捷键不定期整理
- leetCode---Merge k Sorted Lists
- Error:(17, 0) Could not find method android() for arguments [build_1cwiaafm5
- SharePoint online Multilingual support
- Spring MVC初体验
- 蓝桥杯:Huffuman树
- SIP 重定向
- 计算机编码
- Ubuntu16.04虚拟机调整窗口大小自适应VMware10窗口
- HIVE动态分区和动态导入
- Caffe安装中的问题
- ubuntu 16.04下Android studio 编译tensorflow