Last active
July 29, 2019 02:09
-
-
Save cwparsons/6763c2971ff0d35bb999bd2887c03a77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" %> | |
<script runat="server"> | |
// https://patrickdelancy.com/2015/01/compare-contrast-ways-programmatically-publish-sitecore-items/ | |
protected string Result; | |
protected void Page_Load(object sender, System.EventArgs e) | |
{ | |
Result = ""; | |
// Set up the publish mode | |
var publishMode = Sitecore.Publishing.PublishMode.Smart; | |
using (new Sitecore.SecurityModel.SecurityDisabler()) | |
{ | |
// Source db | |
var sourceDatabase = Sitecore.Configuration.Factory.GetDatabase("master"); | |
// Target database | |
var targetDatabase = Sitecore.Configuration.Factory.GetDatabase("web"); | |
try | |
{ | |
foreach (var language in sourceDatabase.Languages) | |
{ | |
// Loops on the languages and do a full republish on the whole sitecore content tree | |
var options = new Sitecore.Publishing.PublishOptions(sourceDatabase, targetDatabase, publishMode, language, System.DateTime.Now) { RootItem = sourceDatabase.Items["/sitecore/Content/Sample tenant"], RepublishAll = true, Deep = true, PublishRelatedItems = true }; | |
var publisher = new Sitecore.Publishing.Publisher(options); | |
var result = publisher.PublishWithResult(); | |
Result += "Publish to Web in " + language.Name + ". Created: " + result.Statistics.Created + "<br><br>"; | |
} | |
Result += "Publish to Web has completed"; | |
} | |
catch (System.Exception ex) | |
{ | |
Result += "Could not publish the master database to the web" + ex.Message + ": " + ex.StackTrace; | |
} | |
} | |
} | |
</script> | |
<%= Result %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment