473,378 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Force Download Not Working


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?

Nov 18 '05 #1
1 1003
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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthew Sims | last post by:
Is it possible to force a download without using the readfile function? My website setup consists of my server that serves the web pages plus a high-speed file server elsewhere on the internet...
4
by: Kevin Muenzler, WB5RUE | last post by:
How do I force a browser to download a file instead of displaying it? In other words I have a page with MP3 and WMA files on it and I would like for the visitor to download the file instead of...
4
by: k.mitz | last post by:
Hi, I have a PHP application that allows users to generate a .pdf report of their database content. Normally, I've had to refresh a page to call the script to generate the report, so there's a...
4
by: tma | last post by:
Short of zipping my file, are there any other alternatives to the below? I'm trying to add anchors in code and I need the link to force a download of the .pdf rather than open a new window or...
0
by: comp.lang.php | last post by:
I have a form that when you click the "Generate Report" submit button, it will force download a CSV file, required for this project. On the very same page you also have a "Search" submit button,...
2
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
3
by: Bouffa | last post by:
Hello everyone, I suppose you all know force-download scripts. The problem is that these scripts don't allow files to be splitted when downloading them via a download manager. I've found a...
1
by: abureach | last post by:
Hi, I cant able to direcly open the file in IE(force download) the follwing code is not working in IE. Please help me my coding is if(ini_get('zlib.output_compression'))
0
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL...
0
by: ridgedale | last post by:
Does anyone know how I can prevent the Acrobat Reader plugin from loading a pdf into the web browser? I need to force the user to download the pdf file and run the pdf using the full Adobe Acrobat...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.