473,388 Members | 1,355 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,388 software developers and data experts.

Forcing Download of File Appends HTML from Download Page to Downloaded File?

Ok, I know this sounds odd. Let me explain further.

I have an ASP.net page (w/ C# code behind) that, when given a session
variable containing the path to a local file, will attempt to start the
download of that file for the user.

Here's the content of my Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
if (Response.IsClientConnected)
{
string fname = Session["fn"].ToString();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition",
"attachment;filename=" +
fname);
Response.WriteFile(fname);
}
}
Somehow, this code will append the html/css code from the download page
to the end of the file being downloaded. For Example, say i'm trying
to download test.txt that contains one line:
----------------------------
This is a test
----------------------------

When i download the file, I get this:

----------------------------
This is a test
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="sf.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNzgzNDMwNTMzZGT/M1xVFtSmiLzmcScAG5lBHRlqGw==" />
</div>

<div></div>
</form>
</body>
</html>
-------------------------

Now, I've tried clearing the Response buffer before sending the file,
but no dice.

Any suggestions?

Jun 16 '06 #1
1 1678
Put a Response.Clear() before your code and a Response.End() after it.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Brett Kelly" <in*****@gmail.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Ok, I know this sounds odd. Let me explain further.

I have an ASP.net page (w/ C# code behind) that, when given a session
variable containing the path to a local file, will attempt to start the
download of that file for the user.

Here's the content of my Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
if (Response.IsClientConnected)
{
string fname = Session["fn"].ToString();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition",
"attachment;filename=" +
fname);
Response.WriteFile(fname);
}
}
Somehow, this code will append the html/css code from the download page
to the end of the file being downloaded. For Example, say i'm trying
to download test.txt that contains one line:
----------------------------
This is a test
----------------------------

When i download the file, I get this:

----------------------------
This is a test
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="sf.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNzgzNDMwNTMzZGT/M1xVFtSmiLzmcScAG5lBHRlqGw==" />
</div>

<div></div>
</form>
</body>
</html>
-------------------------

Now, I've tried clearing the Response buffer before sending the file,
but no dice.

Any suggestions?

Jun 16 '06 #2

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

Similar topics

2
by: mike | last post by:
ok here's the problem: I have a page that displays a form for user to select individual fields and to specify their own criteria which is used to query a database and then create an excel...
2
by: James T Kirk | last post by:
How can I create a link to a zip/exe file, that will start a download and then redirect to another page. The files being downloaded will be different, but the page to be directed to will stay...
2
by: Tom Youngquist | last post by:
I am trying to download a text file that my .NET page has just created based on entered parameters on the web page. Everything seems to work and the file is created. I am using the following code...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
2
by: Ryan Taylor | last post by:
Hello. I am trying to upload a file and save it in a Sql Server 2000 database. This seems to be working fine. However, when I download the file from SQL Server, it appears that the page that is...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.