Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > All files corrupted using Response.Write or Response.BinaryWrite in .NET 1.1

Reply
Thread Tools

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

 
 
ChristopherABurns@gmail.com
Guest
Posts: n/a
 
      10-04-2006
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

 
Reply With Quote
 
 
 
 
m.farbod@gmail.com
Guest
Posts: n/a
 
      11-23-2006
Try commenting out Response.ClearHeaders()


http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ANY ways at all to fix/repair corrupted files? - Please HELP DLee122298@aol.com Computer Information 1 12-12-2008 01:41 PM
Strange behaviour: war files corrupted during upload werner55 Java 2 03-14-2007 09:30 AM
Corrupted dates all over my computer Jim Beaver Computer Support 4 11-06-2006 03:25 AM
Re: Corrupted files on Canon EOS300D when using larger Viking CF cards Ingo Kniest Digital Photography 6 05-26-2005 09:49 PM
PAR2 Files and Corrupted Files english patient Computer Support 3 06-11-2004 02:22 PM



Advertisments