Creating sitecore item programmatically based on template:
public void CreateItemBasedonTemplate()
{
using (new SecurityDisabler())
{
//First get the parent item from the master database
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentItem = masterDb.Items["/sitecore/content/home/MyItem"];
//we need to get the template from which the item is created
TemplateItem template = masterDb.GetTemplate("sample/sample item/My Template");
//Now we can add the new item as a child to the parent
parentItem.Add("NewItem", template);
}
}
{
using (new SecurityDisabler())
{
//First get the parent item from the master database
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentItem = masterDb.Items["/sitecore/content/home/MyItem"];
//we need to get the template from which the item is created
TemplateItem template = masterDb.GetTemplate("sample/sample item/My Template");
//Now we can add the new item as a child to the parent
parentItem.Add("NewItem", template);
}
}
No comments:
Post a Comment