I'm using Sitecore 8.2 and trying to publish an item to 'web' like this:
public static PublishResult PublishItem(string sourceItemPath, Language targetItemLanguage,
string targetDatabaseName, bool publishSubItems)
{
PublishResult publishResult = null;
Item sourceItem = Databases.masterDb.GetItem(sourceItemPath, targetItemLanguage);
if (sourceItem != null)
{
Database targetDatabase = GetDatabase(targetDatabaseName);
if (targetDatabase != null)
{
using (new SecurityDisabler())
{
Sitecore.Publishing.PublishOptions publishOptions =
new Sitecore.Publishing.PublishOptions(Databases.masterDb,
targetDatabase, Sitecore.Publishing.PublishMode.SingleItem,
sourceItem.Language, System.DateTime.Now);
if (publishOptions != null)
{
publishOptions.UserName = Sitecore.Context.User.Name; ;
Sitecore.Publishing.Publisher publisher =
new Sitecore.Publishing.Publisher(publishOptions);
if (publisher != null)
{
publisher.Options.RootItem = sourceItem;
publisher.Options.Deep = publishSubItems;
publishResult = publisher.PublishWithResult(); ///exception here
sourceItem.Publishing.ClearPublishingCache();
}
}
}
}
}
return publishResult;
}
The error is:
One or more exceptions occurred while processing the subscribers to the 'publish:end' event.
When published manually, the item gets published.
Do we need to modify any config setting, when publishing items programmatically.
UPDATE: I changed the publishing statement to this & it worked:
Sitecore.Handle handle = PublishManager.PublishItem(sourceItem, new[] { targetDatabase },
new[] { targetItemLanguage }, publishSubItems, true);
But I would like to get the published statistics like items created/updated/skipped.