public static void download(string fileName, string filepath)
{
string userAgent = HttpContext.Current.Request.Headers.Get("User-Agent");
string f = HttpContext.Current.Server.UrlDecode(fileName);
if (userAgent.Contains("MSIE 7.0"))
{
f = fileName.Replace(" ", "%20");
}
else
{
}
fileName = HttpContext.Current.Server.UrlDecode(fileName);
System.IO.FileStream liveStream = new System.IO.FileStream(HttpContext.Current.Server.MapPath(filepath), System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] buffer = new byte[Convert.ToInt32(liveStream.Length)];
liveStream.Read(buffer, 0, Convert.ToInt32(liveStream.Length));
liveStream.Close();
HttpContext.Current.Response.Clear();
if (fileName.EndsWith(".csv"))
{
HttpContext.Current.Response.ContentType = "application/csv";
}
else
{
HttpContext.Current.Response.ContentType = "application/octet-stream";
}
HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString());
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + f + "\"");
HttpContext.Current.Response.BinaryWrite(buffer);
HttpContext.Current.Response.End();
}