我正在尝试以编程方式创建一个 sitecore 项目。一切正常。但是我创建的项目使用的是“EN-GB”语言,但创建的新项目使用的是“EN”语言。有没有一种方法可以在创建项目时设置语言值。
var currentDatabase = Sitecore.Configuration.Factory.GetDatabase(selectedItem.Database.Name);
if (currentDatabase != null)
{
var rootItem = currentDatabase.GetItem(RootItemPath);
if (rootItem != null)
{
//Create new item
var item = rootItem.Add(selectedItem.Name, CommunityProjectTemplateId);
if (item != null)
{
item.Fields.ReadAll();
item.Editing.BeginEdit();
try
{
//Add values for the fields
item.Fields["Overview Body Content"].Value = selectedItem.GetStringField("ProjectOverview");
}
catch (Exception)
{
item.Editing.EndEdit();
}
}
}
}
最佳答案
您需要在检索根项之前切换上下文语言。
using (new LanguageSwitcher("en-gb"))
{
var rootItem = currentDatabase.GetItem(RootItemPath);
var item = rootItem.Add(selectedItem.Name, CommunityProjectTemplateId);
// Do your editing on item here...
}
关于c# - 以特定语言以编程方式创建 sitecore 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405855/