Skip to content

Instantly share code, notes, and snippets.

@adoprog
Created April 23, 2013 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adoprog/5442120 to your computer and use it in GitHub Desktop.
Save adoprog/5442120 to your computer and use it in GitHub Desktop.
Installing Sitecore update package from code
var files = Directory.GetFiles(Server.MapPath("/sitecore/admin/Packages"), "*.update", SearchOption.AllDirectories);
Sitecore.Context.SetActiveSite("shell");
using (new SecurityDisabler())
{
using (new ProxyDisabler())
{
using (new SyncOperationContext())
{
foreach (var file in files)
{
Install(file);
Response.Write("Installed Package: " + file + "<br>");
}
}
}
}
protected static string Install(string package)
{
var log = LogManager.GetLogger("LogFileAppender");
string result;
using (new ShutdownGuard())
{
var installationInfo = new PackageInstallationInfo
{
Action = UpgradeAction.Upgrade,
Mode = InstallMode.Install,
Path = package
};
string text = null;
List<ContingencyEntry> entries = null;
try
{
entries = UpdateHelper.Install(installationInfo, log, out text);
}
catch (PostStepInstallerException ex)
{
entries = ex.Entries;
text = ex.HistoryPath;
throw;
}
finally
{
UpdateHelper.SaveInstallationMessages(entries, text);
}
result = text;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment