Downloading File Includes HTML ???

G

Guest

Why does the following code include the HTML page in the downloaded file

Response.ContentType="application/x-msdownload";
Response.AddHeader( "content-disposition","attachment; filename=download.txt");
FileStream sourceFile = new FileStream(@"c:\temp\scbdoif.txt", FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.BinaryWrite(getContent);

When I download the file I will see ("<html>.....</html> at the end of the file.
 
B

bruce barker

because they are in the aspx page, whose content is rendered by default. you
can clear the content though:

Response.ClearContent();
Response.BinaryWrite(getContent);
Response.End();

-- bruce (sqlwork.com)




johnz said:
Why does the following code include the HTML page in the downloaded file:

Response.ContentType="application/x-msdownload";
Response.AddHeader( "content-disposition","attachment; filename=download.txt");
FileStream sourceFile = new FileStream(@"c:\temp\scbdoif.txt", FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.BinaryWrite(getContent);


When I download the file I will see ("<html>.....</html> at the end of the
file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top