private void Download() { if (WebConfigSettings.IncludeContentStylesWithSkinExport) { try { string skinPath = Server.MapPath(skinBasePath + skinName); //get the bytes for the style now because we need to compare it to other styletemplate files if any exist. Byte[] styleExportBytes = new UTF8Encoding(true).GetBytes(SkinHelper.GetStyleExportString(siteSettings.SiteGuid)); string[] styleTemplateFiles = Directory.GetFiles(skinPath, "ContentStyles*.xml", SearchOption.TopDirectoryOnly); bool foundMatch = false; if (styleTemplateFiles.Length > 0) { foreach (string existingStyleFile in styleTemplateFiles) { Byte[] existingStyleFileBytes = File.ReadAllBytes(existingStyleFile); if (existingStyleFileBytes.SequenceEqual(styleExportBytes)) { //we found a file which matches the current styles. No need to export them again. foundMatch = true; break; } } } if (!foundMatch) { string fileName = "ContentStyles-" + DateTimeHelper.GetDateTimeStringForFileName() + ".xml"; string fullPath = skinPath + "\\" + fileName; if (!File.Exists(fullPath)) { using (FileStream fs = File.Create(fullPath)) { fs.Write(styleExportBytes, 0, styleExportBytes.Length); } } } } catch (Exception ex) { log.Error("error exporting content styles: " + ex); } } try { using (ZipFile zip = new ZipFile()) { zip.AddDirectory(Server.MapPath(skinBasePath + skinName)); Page.Response.ContentType = "application/zip"; Page.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(skinName + ".zip", Encoding.UTF8) + "\""); // zip.Save(Response.OutputStream); } } catch (ZipException ex) { lblMessage.Text = ex.Message; } }
void btnExportStyles_Click(object sender, EventArgs e) { string fileName = "ContentStyles-" + siteSettings.SiteName + "-" + DateTimeHelper.GetDateTimeStringForFileName() + ".xml"; ExportHelper.ExportStringAsFile(HttpContext.Current, Encoding.Unicode, "text/xml", SkinHelper.GetStyleExportString(siteSettings.SiteGuid), fileName); }