c# - 以特定语言以编程方式创建 sitecore 项目

标签 c# sitecore sitecore6

我正在尝试以编程方式创建一个 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/

相关文章:

c# - ASP.NET MVC 中的身份 cookie 身份验证

c# - 如何使用 OAuth 获取 Google Analytics 数据?

c# - ubuntu 中 vscode 中的 oracle 连接

javascript - Sitecore Javascript 压缩/缩小和 LESS 编译

c# - 子网掩码的正则表达式?

c# - 在 sitecore 中将数据从一个子布局发送到另一个子布局

sitecore - 在代码中查询 Sitecore 数据库有时不返回任何内容

continuous-integration - 如何保持 Sitecore 数据库一致?

c# - 如何以编程方式在 sitecore 中设置 Treelist 的值

lucene - Sitecore Lucene 在 Data\indexes\__system 文件夹中搜索丢失的文件