Add a button in aspx page and write the code in the btnDownload_Click for downloading a excel sheet.
using System;
using System.IO;
using System.Web;
protected void btnDownload_Click(object sender, EventArgs e)
{
try
{
string strSaveFile;
string strFileName="ExcelFileName";
strSaveFile = Server.MapPath(strFileName + ".xls");//Can add doc or any type of files
FileInfo objFileInfo = new FileInfo(strSaveFile);
if (objFileInfo.Exists)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";//Add the type of file you need here..
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + objFileInfo.Name);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.WriteFile(objFileInfo.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}