ASP tutorial. net File Download code
Response.Clear ();
Response.Buffer = true;
Response.contenttype= "Application/vnd.ms-excel";
Response.AddHeader ("Content-disposition", "attachment; Filename=billinginformation_ "+this.ddl_mode.selectedvalue+" ("+system.datetime.now.tostring" ("YYYYMMDD") + "). csv" );
RESPONSE.CONTENTENCODING=SYSTEM.TEXT.ENCODING.UTF7;
Response.charset= "";
Response.Write ("Export Excel file to clients sample");
Response.End ();
DataTable Filedt = Filedao.getfilebyid (Fileid),
byte[] filebytes = (byte[)) filedt.rows[0]["Filedata"];
String originalfilename = filedt.rows[0]["filename"].tostring ();
String randomfilename = Guid.NewGuid (). ToString ();
//download to disk
String filefullpath = This.server.mappath ("~/temp/" + randomfilename);
File.writeallbytes ( Filefullpath, filebytes);
//Send to Client
Response.Clear ();
Response.clearcontent ();
Response.ClearHeaders ();
response.contentencoding = system.text.encoding.getencoding ("Utf-8");
Response.AddHeader ("Content-disposition", "attachment;filename=" + httputility.urlencode (OriginalFilename, System.Text.Encoding.UTF8));
Response.AddHeader ("content-transfer-encoding", "binary");
Response.ContentType = "Application/octet-stream";
Response.WriteFile (Filefullpath);
Response.Flush ();
//delete files on disk
if (file.exists (Filefullpath))
File.delete (filefullpath);
Response.End ();