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

Discussion in 'ASP .Net' started by ChristopherABurns@gmail.com, Oct 4, 2006.

  1. Guest

    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
    , Oct 4, 2006
    #1
    1. Advertising

  2. Guest

    Try commenting out Response.ClearHeaders()


    wrote:
    > 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
    , Nov 23, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charlie@CBFC
    Replies:
    1
    Views:
    2,840
    Arlyn
    May 13, 2005
  2. csgraham74
    Replies:
    0
    Views:
    792
    csgraham74
    Jun 9, 2005
  3. Replies:
    1
    Views:
    415
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jun 1, 2006
  4. Chris  Ashley
    Replies:
    1
    Views:
    616
    bruce barker
    Oct 2, 2007
  5. S N
    Replies:
    0
    Views:
    238
Loading...

Share This Page