473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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 '06 #1
1 9285
Try commenting out Response.ClearHeaders()
Ch***************@gmail.com 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 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PorkyJr | last post by:
Running an asp page that has the following code: <% response.Write MonthName(Month(date)) %> &nbsp; <% response.Write Day(date) %> ,
1
by: news | last post by:
I'm trying to encapsulate a bunch of html widgets such that a containing page can call them to draw themselves in whatever order it chooses as well as easily add new ones. In order to do this...
9
by: msuk | last post by:
All, I have a well form block of XML that is stored in a C# string type and I just simply want to display it in the browser using Response.Write but when I try this I get the following error: ...
11
by: Russ | last post by:
My web app writes some binary data to a file at the client site via Response.Write and Response.BinaryWrite. This action is accomplished in response to a button click, with C# code behind as...
6
by: Abel Chan | last post by:
Hi there, I am trying to use ASP.NET to populate list of files with hyper link from a specific directory. The following code works well but it populates the list to the top of the web page. I...
3
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating...
6
by: Luke Davis | last post by:
I can't figure this out, why am I getting ")" expected and ";" expected on this line? Response.Write("<input type=""hidden"" name=""item_number"" value="".COM, MLSNumber"">"); - L
7
by: Jim in Arizona | last post by:
I'm brand new at ajax. In fact, about 20 minutes ago was the first time I got it to work. The problem I'm having on another page did not work, however. I'm running into the following error: ...
4
by: Abubakar | last post by:
Hi, I'm working on an application whose code was written by some other developer and I dont completely understand its source code right now. In one of the pages where I'm writing a test code, at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.