using System;
using System.Web;
using SiberTek.Xenta.Presentation.Utils;
using SiberTek.Xenta.Web.Utils;
namespace SiberTek.Xenta.Web.FileStorage.Handlers
{
public class DownloadHandler : IHttpHandler
{
#region Properties
public bool IsReusable
{
get
{
return true;
}
}
#endregion
#region Methods
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
try
{
Guid guid = HttpHelper.GetQueryParam<Guid>(context, "Guid");
int fileID = SystemHelper.GetFileID(guid);
byte[] bytes = SystemHelper.ReadFileContent(fileID);
string mimeType = String.Empty;
string fileName = String.Empty;
if(bytes == null)
{
bytes = new byte[] { 0x00 };
}
SystemHelper.GetFileMeta(fileID, ref fileName, ref mimeType);
context.Response.ContentType = mimeType;
context.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName));
context.Response.BinaryWrite(bytes);
}
catch(Exception ex)
{
context.Response.ContentType = "text/plain";
context.Response.Write(ex.Message);
}
context.Response.End();
}
#endregion
}
}