By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,855 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,855 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.