废话不多讲,直接上代码:
using (new SecurityDisabler()) { Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master"); Item parentItem = masterDb.Items["/sitecore/content/my-website/home"]; TemplateItem myTemplate = masterDb.GetTemplate(new ID("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}")); parentItem.Add("my test item ", myTemplate); }
注:对于在bucket里面新建item, 上面代码同样有效~ Sitecore 会自动建bucket folder。