Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Force Download Not Working

Reply
Thread Tools

Force Download Not Working

 
 
localhost
Guest
Posts: n/a
 
      06-29-2004

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?

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      06-30-2004
Hi Localhost,

As for the code snipet you provided, I've also run it in a simple page on
my side, but it seems that it works well and the file open/save dialog is
correctly popup. So I'm not sure whether the problem is due to the client
side. Would you try visiting the page through multi client machine to see
whether the behavior are all the same ? If some other machines can visit
it correctly, I think the problem may due to the particular machine.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM



Advertisments