Saturday, March 19, 2016
Simple way to create Branch Template in Sitecore
Creating sitecore item programmatically based on template
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);
}
}
Friday, March 4, 2016
How To Publish Item CM To CD with c# code
Very simple way to Publish any Item CM To CD using c# code
public static bool PublishItemCMTOCD(Database DbName, String ItemId)
{
Item item = DbName.GetItem(Sitecore.Data. ID.Parse(ItemId));
bool flag = false;
if (item != null)
{
Sitecore.Publishing. PublishOptions publishOptions =
new Sitecore.Publishing. PublishOptions(item.Database,
Database.GetDatabase("web"),
Sitecore.Publishing. PublishMode.SingleItem,
item.Language,
System.DateTime.Now);
Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher( publishOptions);
// Choose where to publish from
publisher.Options.RootItem = item;
// Publish children as well?
publisher.Options.Deep = true;
// Do the publish!
publisher.Publish();
flag = true;
}
return flag;
}
Subscribe to:
Posts (Atom)