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(1)dev
- 從SharePoint 2013遷移到SharePoint Online - 評估工具
- SharePoint Online 自定義Modern UI表單UI
- SharePoint Online 為Modern Page新增指令碼指令碼
- SharePoint Online 觸發 Outlook 郵件內審批
- Web2py App Development CookbookWebAPPdev
- DX: Full Screen GUI Development 2 (轉)GUIdev
- Development log - red & black (2) (轉)dev
- SharePoint Online 站點模板中許可權的設定
- Dynamics 365 Online 利用Microsoft Flow實現自動建立Sharepoint LocationROS
- Perceptron, Support Vector Machine and Dual Optimization Problem (2)Mac
- Veritas Backup Exec™ 21.3 Multilingual (Windows)Windows
- Game Development Methodology for Small Development Teams (轉)GAMdev
- db2 online backup 設定DB2
- game development -- flowGAMdev
- 《Fluid Engine Development》 學習筆記2-基礎UIdev筆記
- 《Expert One-to-One J2EE Design and Development》誰有???dev
- macOS Development - Auto LayoutMacdev
- office365 developmentdev
- What is strategy development process?dev
- BW: 80% of development costsdev
- Web Development Job in 4Webdev
- The server does not support version 3.0 of the J2EE Web module specificationServerWeb
- Support Vector MachinesMac
- Apache JMeter 5.4.1 Build DevelopmentApacheJMeterUIdev
- STM32 Hardware Developmentdev
- PL/SQL development skill testSQLdev
- Java Development Without SpringJavadevSpring
- SharePoint 2016 Beta 2 安裝體驗
- SharePoint REST API - 同步SharePoint列表項RESTAPI
- Announcing MSTest Framework support for .NET Core RC2 / ASP.NET Core RC2[譯]FrameworkASP.NET
- iOS Technical Support For AlliOS
- Types of SAP Support PackagesPackage
- langchain multi modal supportLangChain
- SAP Certified Development Consultant SAP NetWeaver 2004 - Application Development Focus ABAPdevAPP
- 10分鐘精通SharePoint-SharePoint定位
- webpack 開發模式管理 DevelopmentWeb模式dev
- Development Studio 2021,dev