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;
}
No comments:
Post a Comment