Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Forcing Download of File Appends HTML from Download Page to Downloaded File?

Reply
Thread Tools

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

 
 
Brett Kelly
Guest
Posts: n/a
 
      06-16-2006
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?

 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      06-16-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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?
>



 
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
ReportViewer appends a blank page to PDF and Excel Bogdan ASP .Net 0 09-18-2009 04:33 PM
firefox html, my downloaded html and firebug html different? Adam Akhtar Ruby 9 08-16-2008 07:55 PM
Safari 2.0.0.4 appends .html to pdf files Gerrit Horeis ASP .Net 1 05-30-2007 05:28 PM
Forcing a save of a downloaded document teeBull@gmail.com ASP .Net 4 06-27-2006 08:31 AM
File upload/download from database. Download appends aspx page to end of file Ryan Taylor ASP .Net 2 11-10-2004 08:31 PM



Advertisments