ASP.NET,IE6:Download zip file

karakav
karakav used Ask the Experts™
on
I use the code below to provide the user a zip file. The problem is that it doesn't work in Internet Explorer 6. Whe the user try to open the downloaded file, she gets a error saying that the file is corrupt or not valid. Can someone help?
bytes [] data = //get the byte array here
string fileName = //
 
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Length", data.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment;filename=" +fileName);
Response.BinaryWrite(data);
Response.Flush();
Response.Close();
Response.End();

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David RobitailleAnalyst Programmer

Commented:
try this with :
Response.ContentType = "application/zip";

Author

Commented:
I tried that before submitting the question. In vain.
David RobitailleAnalyst Programmer
Commented:
1 -instead of using Response.ClearContent() and Response.ClearHeaders() , try Response.Clear()

2 - how big is the zip file? you could try to send it in chunk (using a for loop)
 check the "Binary Streaming" part of code, at the end of this article:
http://www.codeproject.com/KB/web-image/ImageBinaryStream.aspx
3- are you sure about the zip file; it work with ie7 or firefox?
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Author

Commented:
Response.Clear() doesn't work. Actually when I open the downloaded file with WinRar, I can decompress it without a problem. But when I open with Winzip or Directly through the OS, I get a corrupt file message.
David RobitailleAnalyst Programmer
Commented:
how the zip file is created?
Are you able to save the zip file on the server`s file system and open it? and then, wath happen if you copy it (using a usb key or something) to your computer?

Author

Commented:
Even if I copy the file on another location, I cannot open it without using WinRar.
David RobitailleAnalyst Programmer

Commented:
No,No, No

I'm trying to figure out if the problem is with the file creation process.

 
how the zip file is created?

Are you able to save the zip file on the server`s file system (before sending it)and open it (on the Server)?

and then, waht happen if you copy it (using a usb key or something) from the server to your computer?

Author

Commented:
- how: I sent the snippet above.
 - I can always save the file on the server file system and use Response.TransmitFile but the result is still the same.
 - I don't need to copy from the server because I am still in development.
David RobitailleAnalyst Programmer
Commented:
- how: I sent the snippet above.
in the snippet above, i dont see how you get your "Data"
bytes [] data = //get the byte array here

My point is to validate the fip file before it'S transmitted. because ther is no reason for the file to be "corrupt"

thats why i what you to try to check the "original data". if you got a "working file" on before the transfer, then we could do a file compare to troubleshoot the problem.

here how to sate the bytes in a temp zip file on the server.

http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx
http://msdn.microsoft.com/en-us/library/system.io.filestream.write(VS.80).aspx

Author

Commented:
They are plenty ways of getting a byte array and I don't see the impact this might have on my problem. Besides, I even tried to rebuild up the file from a stream without problem. The problem always arises with transmition over Reponse object.
I am rather interested in doing the file comparison you are proposing.
Analyst Programmer
Commented:
>Besides, I even tried to rebuild up the file from a stream without problem.
good, that what i want to know.

Well, there is many file comparison software on the market. I have a licenced copy of one of them. i think it's active file compare or something like that. But a quick search on google will allow you to find Manny.

A text editor (my favourite is PSPad) could also do the job for what we are going to do. PSPad is free and it have some basic file comparison tools.

First thing you need to do is to check the length of the files. is the file transmitted completely?
also check the start and the end of the file. check for thing like unwanted header/footer bytes.

Finally you could do a bytes-to-bytes comparison using any tool I talked about in this thread.

David RobitailleAnalyst Programmer
Commented:
How it`s going??? what are the differences between the files???
I also just remember, there is another way to send a file that use a for loop to send them in smaller "packet". Tell my if you need more info about that.
FYI, I just checked and the name of the tool i usually use for file compare is "Beyond Compare" (v2)
 

Author

Commented:
Sorry for the delay, I was out last week and I couldn't react on your comments on time. I started to play out with the tool you mentioned, and digning in I found that actually the problem was not my code. The compressend files I was checkin was made with WinRar and I guess that there something in there that make the compressed file incompatible with other decompressing tools. I used vista integrated tool to make some compressed file and I was able to open them without problems.

By the way, if I may abuse, I would like to know about the other alternative way to send file you mentioned.
David RobitailleAnalyst Programmer

Commented:
"The compressend files I was checkin was made with WinRar and I guess that there something in there that make the compressed file incompatible with other decompressing tools"
Thats what i was suspecting from my 3th comment. That why i asked to try to copy the file by others means than the file downloading...
 
For the other alternative, I just realize i sent it in my second comments:
check the "Binary Streaming" part of code, at the end of this article:
http://www.codeproject.com/KB/web-image/ImageBinaryStream.aspx
 

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial