如何在Sitecore中以编程方式创建项目并实现高效管理?

2026-03-30 11:511阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计351个文字,预计阅读时间需要2分钟。

如何在Sitecore中以编程方式创建项目并实现高效管理?

在内容树中,结构如下:Home - England - France - Germany,含有一个子布局(CommentsForm.ascx),用于所有三个页面。用户浏览法国并提交评论时,评论项目应保存到法国下,继续此类推。在这种情况下,继续此类推。

在内容树中,结构如下

Home -England -France -Germany

有一个子布局(CommentsForm.ascx),用于所有3个页面.当用户浏览“法国”并提交评论时,“评论”项目应保存在“法国”下,依此类推.

在这种情况下,父项(必须在其下创建新项)是动态的.那么,在这种情况下如何获取父项.它是否正确?

如何在Sitecore中以编程方式创建项目并实现高效管理?

protected void btnSubmit_Click(object sender, EventArgs e) { Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = Sitecore.Context.Item; string name = "Comment_" + Sitecore.DateUtil.IsoNow; TemplateItem template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment"); using (new SecurityDisabler()) { //how to go about here?? //newItem["Author"] = txtAuthor.text; //newItem["CommentText"] = txtComments.Text; //parentItem.Add("name", template); } } 您可以在生产中使用UserSwitcher更安全,但您也可以使用SecurityDisabler(newSecurityDisabler()){}

编辑和重命名必须在Editing.BeginEdit()事务中进行

Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = Sitecore.Context.Item; string name = "Comment_" + Sitecore.DateUtil.IsoNow; var template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment"); using (new Sitecore.SecurityModel.SecurityDisabler()) { try { Item newItem = parentItem.Add("Name", template); if (newItem!=null) { newItem.Editing.BeginEdit(); newItem["Author"] = txtAuthor.text; newItem["CommentText"] = txtComments.Text; newItem.Editing.EndEdit(); } } catch { newItem.Editing.CancelEdit(); } }

本文共计351个文字,预计阅读时间需要2分钟。

如何在Sitecore中以编程方式创建项目并实现高效管理?

在内容树中,结构如下:Home - England - France - Germany,含有一个子布局(CommentsForm.ascx),用于所有三个页面。用户浏览法国并提交评论时,评论项目应保存到法国下,继续此类推。在这种情况下,继续此类推。

在内容树中,结构如下

Home -England -France -Germany

有一个子布局(CommentsForm.ascx),用于所有3个页面.当用户浏览“法国”并提交评论时,“评论”项目应保存在“法国”下,依此类推.

在这种情况下,父项(必须在其下创建新项)是动态的.那么,在这种情况下如何获取父项.它是否正确?

如何在Sitecore中以编程方式创建项目并实现高效管理?

protected void btnSubmit_Click(object sender, EventArgs e) { Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = Sitecore.Context.Item; string name = "Comment_" + Sitecore.DateUtil.IsoNow; TemplateItem template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment"); using (new SecurityDisabler()) { //how to go about here?? //newItem["Author"] = txtAuthor.text; //newItem["CommentText"] = txtComments.Text; //parentItem.Add("name", template); } } 您可以在生产中使用UserSwitcher更安全,但您也可以使用SecurityDisabler(newSecurityDisabler()){}

编辑和重命名必须在Editing.BeginEdit()事务中进行

Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = Sitecore.Context.Item; string name = "Comment_" + Sitecore.DateUtil.IsoNow; var template = masterDb.GetTemplate("/sitecore/templates/userdefined/Comment"); using (new Sitecore.SecurityModel.SecurityDisabler()) { try { Item newItem = parentItem.Add("Name", template); if (newItem!=null) { newItem.Editing.BeginEdit(); newItem["Author"] = txtAuthor.text; newItem["CommentText"] = txtComments.Text; newItem.Editing.EndEdit(); } } catch { newItem.Editing.CancelEdit(); } }