博客地址: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的代码如下所示:

  1. private static void CreateSiteColumn(ClientContext cc, Web web)
  2. {
  3. // Add site column to the content type if it's not there...
  4. FieldCollection fields = web.Fields;
  5. cc.Load(fields);
  6. cc.ExecuteQuery();
  7.  
  8. foreach (var item in fields)
  9. {
  10. if (item.InternalName == "ContosoString")
  11. return;
  12. }
  13.  
  14. string FieldAsXML = @"<Field ID='{4F34B2ED-9CFF-4900-B091-4C0033F89944}'
  15. Name='ContosoString'
  16. DisplayName='Contoso String'
  17. Type='Text'
  18. Hidden='False'
  19. Group='Contoso Site Columns'
  20. Description='Contoso Text Field' />";
  21. Field fld = fields.AddFieldAsXml(FieldAsXML, true, AddFieldOptions.DefaultValue);
  22. cc.Load(fields);
  23. cc.Load(fld);
  24. cc.ExecuteQuery();
  25. }

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

  1. private static void CreateContentTypeIfDoesNotExist(ClientContext cc, Web web)
  2. {
  3. ContentTypeCollection contentTypes = web.ContentTypes;
  4. cc.Load(contentTypes);
  5. cc.ExecuteQuery();
  6.  
  7. foreach (var item in contentTypes)
  8. {
  9. if (item.StringId == "0x0101009189AB5D3D2647B580F011DA2F356FB2")
  10. return;
  11. }
  12.  
  13. // Create a Content Type Information object
  14. ContentTypeCreationInformation newCt = new ContentTypeCreationInformation();
  15. // Set the name for the content type
  16. newCt.Name = "Contoso Document";
  17. //Inherit from oob document - 0x0101 and assign
  18. newCt.Id = "0x0101009189AB5D3D2647B580F011DA2F356FB2";
  19. // Set content type to be avaialble from specific group
  20. newCt.Group = "Contoso Content Types";
  21. // Create the content type
  22. ContentType myContentType = contentTypes.Add(newCt);
  23. cc.ExecuteQuery();
  24. }

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

  1. private static void AddSiteColumnToContentType(ClientContext cc, Web web)
  2. {
  3. ContentTypeCollection contentTypes = web.ContentTypes;
  4. cc.Load(contentTypes);
  5. cc.ExecuteQuery();
  6. ContentType myContentType = contentTypes.GetById("0x0101009189AB5D3D2647B580F011DA2F356FB2");
  7. cc.Load(myContentType);
  8. cc.ExecuteQuery();
  9.  
  10. FieldCollection fields = web.Fields;
  11. Field fld = fields.GetByInternalNameOrTitle("ContosoString");
  12. cc.Load(fields);
  13. cc.Load(fld);
  14. cc.ExecuteQuery();
  15.  
  16. FieldLinkCollection refFields = myContentType.FieldLinks;
  17. cc.Load(refFields);
  18. cc.ExecuteQuery();
  19.  
  20. foreach (var item in refFields)
  21. {
  22. if (item.Name == "ContosoString")
  23. return;
  24. }
  25.  
  26. // ref does nt
  27. FieldLinkCreationInformation link = new FieldLinkCreationInformation();
  28. link.Field = fld;
  29. myContentType.FieldLinks.Add(link);
  30. myContentType.Update(true);
  31. cc.ExecuteQuery();
  32. }

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

  1. private static void LocalizeContentTypeAndField(ClientContext cc, Web web)
  2. {
  3. ContentTypeCollection contentTypes = web.ContentTypes;
  4. ContentType myContentType = contentTypes.GetById("0x0101009189AB5D3D2647B580F011DA2F356FB2");
  5. cc.Load(contentTypes);
  6. cc.Load(myContentType);
  7. cc.ExecuteQuery();
  8. // Title of the content type
  9. myContentType.NameResource.SetValueForUICulture("en-US",
  10. "Contoso Document");
  11. myContentType.NameResource.SetValueForUICulture("fi-FI",
  12. "Contoso Dokumentti");
  13. myContentType.NameResource.SetValueForUICulture("fr-FR",
  14. "Contoso Document (FR)");
  15. // Description of the content type
  16. myContentType.DescriptionResource.SetValueForUICulture("en-US",
  17. "This is the Contoso Document.");
  18. myContentType.DescriptionResource.SetValueForUICulture("fi-FI",
  19. "Tämä on geneerinen Contoso dokumentti.");
  20. myContentType.DescriptionResource.SetValueForUICulture("fr-FR",
  21. "French Contoso document.");
  22. myContentType.Update(true);
  23. cc.ExecuteQuery();
  24.  
  25. // Do localization also for the site column
  26. FieldCollection fields = web.Fields;
  27. Field fld = fields.GetByInternalNameOrTitle("ContosoString");
  28. fld.TitleResource.SetValueForUICulture("en-US", "Contoso String");
  29. fld.TitleResource.SetValueForUICulture("fi-FI", "Contoso Teksti");
  30. fld.TitleResource.SetValueForUICulture("fr-FR", "Contoso French String");
  31. // Description entry
  32. fld.DescriptionResource.SetValueForUICulture("en-US",
  33. "Used to store Contoso specific metadata.");
  34. fld.DescriptionResource.SetValueForUICulture("fi-FI",
  35. "Tää on niiku Contoso metadatalle.");
  36. fld.DescriptionResource.SetValueForUICulture("fr-FR",
  37. "French Description Goes here");
  38. fld.UpdateAndPushChanges(true);
  39. cc.ExecuteQuery();
  40. }

跟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(1)

    博客地址: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 (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 ...

  9. [IT学习]微软如何做网站内容治理

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

随机推荐

  1. You Don't Know JS: Scope & Closures (第2章: Lexical Scope)

    2种主要的models for how scope work. 最普遍的是Lexical Scope. 另一种 Dynamic Scope.(在Appendix a中介绍.和Lexical Scope ...

  2. codeforces708b// Recover the String //AIM Tech Round 3 (Div. 1)

    题意:有一个01组成的串,告知所有长度为2的子序列中,即00,01,10,11,的个数a,b,c,d.输出一种可能的串. 先求串中0,1的数目x,y. 首先,如果00的个数a不是0的话,设串中有x个0 ...

  3. 2019/01/17 基于windows使用fabric将gitlab的文件远程同步到服务器(git)

    觉得django项目把本地更新push到gitlab,再执行fabric脚本从gitlab更新服务器项目挺方便的,当然从本地直接到服务器就比较灵活. 2019/01/17 基于windows使用fab ...

  4. php 常用设计模式demo

    <?php//__get()//__set()当对象中属性不存在时调用该魔术方法//__call()当对象中方法不存在时//__callStatic()静态方法//__string()当对象不能 ...

  5. 欧拉函数 牛客寒假1 小a与黄金街道

    题目链接 分析:这题用到了欧拉函数, 欧拉函数,用φ(n)表示 欧拉函数是求小于等于n的数中与n互质的数的数目 详细可以看看这篇博文https://www.cnblogs.com/linyujun/p ...

  6. Jupyter Notebook入门教程

    Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言.在本文中,我们将介绍 Jupyter notebook 的主要特性,以 ...

  7. springboot项目线程使用

    下面是一个demo: public class TestThread { private static int nThreads =Runtime.getRuntime().availableProc ...

  8. [转]2017年最具价值的十大开源项目!GitHub 年度报告~

    <GitHub 2017 年度报告>GitHub 每年都会在年度盛会中推出数据报告,其中列出了一些年度的数据,包括其网站中最受欢迎的编程语言.开源项目等.那么今年哪些开源项目最具价值呢?我 ...

  9. <Closing connections idle longer than 60000 MILLISECONDS> <Closing expired connections>

    日志信息如下: 2017-07-05 18:28:34 -18705 [idle_connection_reaper] DEBUG   - Closing expired connections 20 ...

  10. NOIP2006能量项链

    题目描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数.并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定 ...