473,597 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, EventArgs e)
{
if (Response.IsCli entConnected)
{
string fname = Session["fn"].ToString();
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition",
"attachment;fil ename=" +
fname);
Response.WriteF ile(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.dt d">

<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="__VIEWSTA TE" id="__VIEWSTATE "
value="/wEPDwUJNzgzNDMw NTMzZGT/M1xVFtSmiLzmcSc AG5lBHRlqGw==" />
</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 1687
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.goo glegroups.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(objec t sender, EventArgs e)
{
if (Response.IsCli entConnected)
{
string fname = Session["fn"].ToString();
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition",
"attachment;fil ename=" +
fname);
Response.WriteF ile(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.dt d">

<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="__VIEWSTA TE" id="__VIEWSTATE "
value="/wEPDwUJNzgzNDMw NTMzZGT/M1xVFtSmiLzmcSc AG5lBHRlqGw==" />
</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
2316
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 spreadsheet and download it to their PC. when the user clicks on the "create a custom query" link on the reports page the file customss.php displays the form that list the various fields and criteria to specify for the search. This part
2
21789
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 the same. I want the redirect to happen as soon as the download begins... How can I do this ?
2
1998
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 to start the download process: Response.Clear() Response.ContentType = "text/plain" Response.AppendHeader("Content-Disposition", "attachment; filename=" & fileName) Response.AppendHeader("Content-Description", "This is your Cost Journal...
0
1822
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 window. Well, thanks to Steve Orr, I have that working. However, I still have a few issues. First, the download dialog does not have the name of the file being downloaded in the "File name" field, instead it has the name of the aspx page that have...
2
1828
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 downloading this file is being appended to the end of the file. So I am accidently modifiying every file that is placed in the database. What follows is my code for uploading and downloading a file, minus the sql code to insert/retrieve the data...
0
1735
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, identifies the template required then uses Response.AppendHeader to amend the response to create the file download dialogue. On my local machine this works fine and the download dialogue correctly identifies the file name and type attempting to be...
5
12285
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. On Beta1, I am able to execute a particular page with no problem, that page opens up in the comes up just fine. On Win2kdev1, when I go to execute the same page, it opens a file download dialog and asks me whether I want to open or save the...
16
3236
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 not print in the username or email amddress of the person doing the download - which I am collecting from a form on the previous page. I can get the name and email address to print out normally, just not into the email sending body. I have...
1
47433
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
8254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5842
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5421
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3876
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2393
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.