sitecore Items Publish Sitecore item programmatically


When publishing Sitecore item programmatically the developer should keep in mind that Sitecore could be configured for several publishing targets, as well that several languages could be defined for item.

ID targetDatabaseFieldId = ID.Parse("{39ECFD90-55D2-49D8-B513-99D15573DE41}");

     var publishingDatabases =
                                .Select(i => i[targetDatabaseFieldId]) //Get Target Database value
                                .Where (i => i != null)
                                .Select(i => Database.GetDatabase(i))
                        PublishManager.PublishItem(mediaItem, publishingDatabases,
                            LanguageManager.GetLanguages(StaticSettings.WebDatabase).ToArray(), false, false);