- File has to be saved to hard drive on server
- Create a link button and write the following code at the <button>_Click event.(Replace your filename with location at "<filename>")
System.IO.FileStream fs = null;
fs = System.IO.File.Open(<filename>,FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.Buffer = true;
Response.Expires = 0;
Response.ContentType = "plain/text";
Response.AddHeader("Content-Type", "plain/text");
//Response.AddHeader("Content-Length", btFile.Length.ToString);
Response.AddHeader("Content-Disposition", "attachment;filename=" + Session["downloadFname"].ToString());
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(btFile);
Response.End();
byte[] fileC = File.ReadAllBytes(<filename>);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+ <filename> );
HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
HttpContext.Current.Response.AppendHeader("Pragma", "public");
HttpContext.Current.Response.AppendHeader("Expires", "0");
HttpContext.Current.Response.OutputStream.Write(fileC, 0, fileC.Length);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();
Response.Clear();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.AppendHeader("Content-Disposition", "attachment; filename="+<filename>);
Response.TransmitFile(recapPath + fname);
Response.Clear();
Response.Flush();
Response.End();Response.ContentType = "text/txt";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + <filename> + ".txt");
Page.Response.WriteFile(<filename with extention>);
Response.End();System.IO.FileStream fs = null;
fs = System.IO.File.Open(<filename>, FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + <filename>);
Response.ContentType = "plain/text";
UTF8Encoding encoding = new UTF8Encoding();
Response.BinaryWrite(btFile);
Response.Flush();
Response.End();System.IO.FileStream fs = null;
fs = System.IO.File.Open(<filename>, FileMode.Open);
byte[] btFile = new byte[fs.Length];
fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.Buffer = true;
Response.Expires = 0;
Response.ContentType = "plain/text";
Response.AddHeader("Content-Type", "plain/text");
Response.AddHeader("Content-Length", btFile.Length.ToString);
Response.AddHeader("Content-Disposition", "attachment;filename=" + <filename>);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(btFile );
Response.End();

Punith NagarajPosted Jul 17, 2014, 12:26 AM
But it can be Optimized...
Punith NagarajPosted Jul 17, 2014, 12:26 AM
Super
yatendra shekhawatPosted Jul 4, 2012, 5:09 AM
fgfdgfgfdgdfgfdgfdgdfgfdg