473,406 Members | 2,387 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,406 software developers and data experts.

Download file has HTML in it.

i have a file on the server, then use the following code to dialog the
file to the local client.
in stepping through the code the file length (fLen) is correct, but
when i look at the file after
download, it has all the HTML markup appended to the file. i've played
with this a number of
different ways but to no avail.

any help is much appreciated.
string root = @"C:\temp\";
string filepath = @"C:\temp\tempo_file.csv";
FileInfo fyl = new FileInfo(filepath);
string fLen = fyl .Length.ToString();
if ((filepath != null))
{
if (File.Exists(filepath) & filepath.StartsWith(root))
{
Response.Clear();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Length", fLen);
Response.AddHeader("Content-Disposition", "attachment;
filename=\"" + fyl.Name + "\"");
Response.Flush();
Response.TransmitFile(filepath);
}
}

thanks...

-fd
Jun 27 '08 #1
2 992
In the ASPX portion of the page, you need to remove ALL markup except for the
@Page declaration line.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net
"forest demon" wrote:
i have a file on the server, then use the following code to dialog the
file to the local client.
in stepping through the code the file length (fLen) is correct, but
when i look at the file after
download, it has all the HTML markup appended to the file. i've played
with this a number of
different ways but to no avail.

any help is much appreciated.
string root = @"C:\temp\";
string filepath = @"C:\temp\tempo_file.csv";
FileInfo fyl = new FileInfo(filepath);
string fLen = fyl .Length.ToString();
if ((filepath != null))
{
if (File.Exists(filepath) & filepath.StartsWith(root))
{
Response.Clear();
Response.ContentType = "text/plain";
Response.AddHeader("Content-Length", fLen);
Response.AddHeader("Content-Disposition", "attachment;
filename=\"" + fyl.Name + "\"");
Response.Flush();
Response.TransmitFile(filepath);
}
}

thanks...

-fd
Jun 27 '08 #2
On Apr 12, 6:23*am, Peter Bromberg [C# MVP]
<pbromb...@yahoo.NoSpamMaam.comwrote:
In the ASPX portion of the page, you need to remove ALL markup except for the
@Page declaration line.
-- Peter
Site:http://www.eggheadcafe.com
UnBlog:http://petesbloggerama.blogspot.com
Short Urls & more:http://ittyurl.net

"forest demon" wrote:
i have a file on the server, then use the following code to dialog the
file to the local client.
in stepping through the code the file length (fLen) is correct, but
when i look at the file after
download, it has all the HTML markup appended to the file. i've played
with this a number of
different ways but to no avail.
any help is much appreciated.
string root = @"C:\temp\";
string filepath = @"C:\temp\tempo_file.csv";
FileInfo fyl = new FileInfo(filepath);
string fLen = fyl .Length.ToString();
if ((filepath != null))
{
* * *if (File.Exists(filepath) & filepath.StartsWith(root))
* * *{
* * * * * Response.Clear();
* * * * * Response.ContentType = "text/plain";
* * * * * Response.AddHeader("Content-Length", fLen);
* * * * * Response.AddHeader("Content-Disposition", "attachment;
filename=\"" + fyl.Name + "\"");
* * * * * Response.Flush();
* * * * * Response.TransmitFile(filepath);
* * * }
}
thanks...
-fd- Hide quoted text -

- Show quoted text -
i had that originally, but couldn't find a successful way to close the
blank window that pops.

-fd
Jun 27 '08 #3

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

Similar topics

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...
3
by: James Kirk | last post by:
The script below allows me to link to a file and as the user clicks to download, the 'File Download' windows appears as normal, and the user can download... The original page is then redirected...
6
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This...
5
by: Thomas Andersson | last post by:
Hi, I am trying to find a working solution for download of large files (400-800 MB)... But this seems almost impossible to find a working example. I have tried Response.Transmitfile, this...
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,...
1
by: Brett Kelly | last post by:
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...
2
by: Jan Paul van de Berg | last post by:
I have a piece of software that people can download and a third party promoting that software. In order for them to be able to count the number of downloads, I have to put a tracking code on my...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
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: 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: 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
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...
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:
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...
0
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...

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.