2016-10-11 95 views
0

当我尝试为现有模板创建新项目时,我是sitecore的新手。我无法调用我的主数据库。需要一些关于如何在sitecore中创建新项目以及如何在运行的sitecore页面上显示它的指南?只需要关于创建后流程的一些提示如何在现有sitecore页面上呈现它。从现有模板创建Sitecore项目

<configuration type="Sitecore.Search.SearchConfiguration, Sitecore.Kernel" singleInstance="true"> 
     <indexes hint="list:AddIndex"> 
      <index id="system" type="Sitecore.Search.Index, Sitecore.Kernel"> 
      <param desc="name">$(id)</param> 
      <param desc="folder">__system</param> 
      <Analyzer ref="search/analyzer" /> 
      <locations hint="list:AddCrawler"> 
       <core type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel"> 
       <Database>core</Database> 
       <Root>/sitecore/content</Root> 
       <include hint="list:IncludeTemplate"> 
        <application>{EB06CEC0-5E2D-4DC4-875B-01ADCC577D13}</application> 
       </include> 
       <Tags>application</Tags> 
       <Boost>2.0</Boost> 
       </core> 
       <core-controlpanel type="Sitecore.Search.Crawlers.DatabaseCrawler,Sitecore.Kernel"> 
       <Database>core</Database> 
       <Root>/sitecore/content/applications/control panel</Root> 
       <include hint="list:IncludeTemplate"> 
        <taskoption>{BDB6FA46-2F76-4BDE-8138-52B56C2FC47E}</taskoption> 
       </include> 
       <Tags>taskoption</Tags> 
       <Boost>1.9</Boost> 
       </core-controlpanel> 
       <master type="Sitecore.Search.Crawlers.DatabaseCrawler, Sitecore.Kernel"> 
       <Database>master</Database> 
       <Tags>master content</Tags> 
       </master> 
      </locations> 
      </index> 
     </indexes> 
     </configuration> 

回答

1

我会写我的代码通常执行:

Database database = Database.GetDatabase("master"); 
Item rooItem = database.GetItem(new ID(parentItemId)); 
if (rootItem == null) return null; 

TemplateID pageTemplateId = new TemplateID(new ID(templateId)); 
string validName = ItemUtil.ProposeValidItemName(name); 

using (new Sitecore.SecurityModel.SecurityDisabler()) 
{ 
    Item newItem = rootItem.Add(validName, pageTemplateId); 
    if (newItem == null) return null; 
    //TODO: publish item 
} 
  • rootItem可能是家里项目
  • templateId将是你的页面模板的id(记住这页应该有布局和效果图定义)
+0

谢谢@ Santiago Morla,但我在GetDatabase中出错。因为“无法读取Sitecore配置” –

+0

你检查了你的web.config文件吗?该错误意味着您的配置中没有节点。 你可以做的是给予该文件夹适当的权限 - (取消选中只读属性) –

+0

它在我的web.config文件中以