All files corrupted using Response.Write or Response.BinaryWrite in .NET 1.1

  • Thread starter ChristopherABurns
  • Start date
C

ChristopherABurns

I have a very simple code snippet here:

private void Page_Load(object sender, System.EventArgs e)
{
string filePath =
Server.MapPath("\\Transcriber\\TranscriberTest\\");
string fileName = "Test.Zip";
//FileInfo fi = new FileInfo(filePath + fileName);
FileStream fs = File.Open(filePath + fileName,FileMode.Open);

byte[] fileData = new byte[fs.Length];
fs.Write(fileData,0,(int)fs.Length);
fs.Close();

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();

HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader("Content-disposition",
"attachment; filename=" + fileName);
HttpContext.Current.Response.BinaryWrite(fileData);
//HttpContext.Current.Response.WriteFile(filePath +
fileName,0,(int)fi.Length);
HttpContext.Current.Response.End();

}

<end snippet>

No matter what I tweak, the Zip file (I have tried .MP3, PDF to no
avail as well) is corrupt.
I have tried application/octet-stream and application/x-unkown for the
ContentType.

BinaryWrite, and A straight writefile produce the same results - a
corrupt file.

Anyone feeling charitable out there?

Thanks,
Chris
 

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

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top