Mick

Mick

  • NA
  • 3
  • 0

Downloading files from a server (.NET, ASP, C#)

Aug 30 2005 11:55 AM

I am trying to download a file from a Windows 2000 server using the following code:

string
fileName = System.IO.Path.GetFileName(strFilePath);
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.ContentType = "text/HTML";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
// Make sure the client is still connected.
if
(Response.IsClientConnected)
{
   Response.TransmitFile(strFilePath);
   Response.Flush();
}

However, along with the file data, the HTML from the ASP page is also downloaded!
I have also tried code using "Response.Output.Write(bBuffer, 0, nBytesRead);"

If anyone has an idea about why the HTML is being appended, and how to stop it, I would be grateful!

Thanks
Mick


Answers (3)