I need to publish a specific version of item to be published programmatically. Let's say I have item AboutUs which workflow enabled and have a total of 15 versions. The 10th version is already in final state and the rest are draft state. Then I add version 10 to my custom scheduled publishing task.
When the task is triggered and published successfully, it is the latest version published, even still in draft state.
Here's my current code:
PublishOptions publishOptions = new PublishOptions(sourceDb, targetDb, PublishMode.Smart, LanguageManager.DefaultLanguage, DateTime.Now);
publishOptions.Deep = isDeepPublish;
publishOptions.RepublishAll = false;
publishOptions.RootItem = itemToPublish;
Publisher publisher = new Publisher(publishOptions);
publisher.Publish();
When debugging, itemToPublish.Version returned version 10, which is the correct one.
I've also tried with :
PublishManager.PublishItem(itemToPublish, new Database[] { targetDb }, targetDb.Languages, isDeepPublish, false);
Yes, it works to publish the correct version, but somehow I got weirdness. Sometimes it would unpublish, sometimes field values are empty, sometimes not working at all. Also, it's not immediately published.
I'm using Sitecore 8.2 Initial Release