Created
March 12, 2015 20:40
-
-
Save JRondeau16/3dfc00bfe73af6eab362 to your computer and use it in GitHub Desktop.
ExportControl
This file contains 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
using System; | |
using System.IO; | |
using System.Web; | |
using Sitecore.IO; | |
using Sitecore.Form.Core.Utility; | |
namespace MyProject | |
{ | |
public partial class ExportBinary : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
var text = Session["exportcontent"] as byte[]; //may need to change depending on the type of file | |
var filename = Session["filename"] as string; | |
if (string.IsNullOrEmpty(filename) || text == null || text.Length.Equals(0)) | |
return; | |
Sitecore.Diagnostics.Log.Info(string.Format("Exporting my custom file {0}", filename), this); | |
var tempFileName = WebUtil.GetTempFileName(); | |
File.WriteAllBytes(tempFileName, text); //may need to change depending on the type of file | |
var fileSize = FileUtil.GetFileSize(tempFileName); | |
WriteCacheHeaders(filename, fileSize); | |
Response.TransmitFile(tempFileName, 0L, fileSize); | |
Response.End(); | |
} | |
private void WriteCacheHeaders(string filename, long length) | |
{ | |
HttpResponse response = HttpContext.Current.Response; | |
response.ClearHeaders(); | |
response.AddHeader("Content-Type", (string)Session["contentType"] ?? "application/octet-stream"); | |
response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); | |
response.AddHeader("Content-Length", length.ToString()); | |
response.Cache.SetNoStore(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment