December 17, 2011

C# Code to download the file

using

{




System.IO;private void DownloadFile(string fname, bool forceDownload)string path = MapPath(@"~\Forms\" + fname);string name = Path.GetFileName(path);string ext = Path.GetExtension(path);string type = "";// set known types based on file extension
{

{


type =


type =



type =

}
}

{
Response.AppendHeader(
}


Response.ContentType = type;
Response.WriteFile(path);
Response.End();
}


{
DownloadFile(
}
if (ext != null)switch (ext.ToLower())case ".htm":case ".html":"text/HTML";break;case ".txt":"text/plain";break;case ".doc":case ".rtf":"Application/msword";break;if (forceDownload)"content-disposition", "attachment; filename=" + name);if(type != "")protected void imgMoblileAdd_Click(object sender, ImageClickEventArgs e)"filename.pdf", true);

No comments:

Post a Comment