L
localhost
I have a text file that I need web users to get as a "forced download"
instead of displaying in the browser. The following Page_Load code is
not working, what did I miss?
private void Page_Load(object sender, System.EventArgs e)
{
string sendText = "[empty]";
if ( Session["sendText"] != null )
{
sendText = Session["sendText"].ToString();
}
ASCIIEncoding asciiEncoding = new ASCIIEncoding();
byte[] sendBytes = asciiEncoding.GetBytes( sendText );
MemoryStream memoryStream = new MemoryStream( sendBytes );
Response.ClearContent();
Response.ClearHeaders();
//Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length",
memoryStream.Length.ToString() );
Response.AddHeader("Content-Disposition", "attachment;
filename=bs.bad" );
//Response.Charset = "UTF-8";
Response.BinaryWrite(sendBytes);
Response.Flush();
Response.End();
}
If you run that, you will just see "[empty]" instead of a save dialog.
Help?
instead of displaying in the browser. The following Page_Load code is
not working, what did I miss?
private void Page_Load(object sender, System.EventArgs e)
{
string sendText = "[empty]";
if ( Session["sendText"] != null )
{
sendText = Session["sendText"].ToString();
}
ASCIIEncoding asciiEncoding = new ASCIIEncoding();
byte[] sendBytes = asciiEncoding.GetBytes( sendText );
MemoryStream memoryStream = new MemoryStream( sendBytes );
Response.ClearContent();
Response.ClearHeaders();
//Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length",
memoryStream.Length.ToString() );
Response.AddHeader("Content-Disposition", "attachment;
filename=bs.bad" );
//Response.Charset = "UTF-8";
Response.BinaryWrite(sendBytes);
Response.Flush();
Response.End();
}
If you run that, you will just see "[empty]" instead of a save dialog.
Help?