So this is primary a little code sniplet that will enable you to da a publish on a item. The method will probably exist in each of your Sitecore projects, as its a fundamental method to use. In the old days we used to put it in a utility class, making it static. Now i would make an extension class extening the Item object with the publish options.
The most general publishing method looks like this
/// <summary> /// Most general mothod for pubishing an item /// </summary> /// <param name="item">the item to publish</param> /// <param name="includeSubitems">should subitems also be published</param> /// <param name="sourceDatabase">from this database</param> /// <param name="targetDatabase">to this database</param> /// <param name="async">should the publish be async</param> /// <returns>a Job item containing the publisher, if async is true</returns> public static Job PublishItem(this Item item, bool includeSubitems, Database sourceDatabase, Database targetDatabase, bool async) { Assert.IsNotNull(item, "item is null"); Assert.IsNotNull(sourceDatabase, "sourceDatabase is null"); Assert.IsNotNull(targetDatabase, "targetDatabase is null"); var options = new PublishOptions(sourceDatabase, targetDatabase, PublishMode.SingleItem, LanguageManager.DefaultLanguage, DateTime.Now); options.Deep = includeSubitems; options.CompareRevisions = true; options.RootItem = item; var publisher = new Publisher(options); if (!async) { publisher.Publish(); return null; } else { return publisher.PublishAsync(); } }
the above code will publish an item, with the options you want, you can eighther include subitems, or just publish the single item, you ar also able to change which databases shuold be source and target. In most cases this would be master to web, but when using staging, you could have more web databases that should be published to.
Ive attached the cs file that contains a few overloads and the above mothod in this file: ItemExtensions.cs (3.89 kb)