Zip File Download Error!!!

V

Vai2000

Hi All, I am trying to allow clients to download zipped file from my system
using the code below. Apparently the file gets downloaded but when the users
try opening the file with WinZip they get problem saying
Cannot open this file: it doesn't appear to be a valid archive. If you
downloaded this file, try downloading the file again.

When I open the compressed file on the server, its fine.

Any clues?

TIA

using(FileStream fs=new FileStream(compressedFileNm,FileMode.Open))
{
byte [] data=new Byte[fs.Length];
BinaryReader br=new BinaryReader(fs);
br.Read(data,0,data.Length);
br.Close();

Response.ContentType="application/x-zip-compressed";
Response.AppendHeader("Content-Disposition","filename="
+compressedFileNm);
Response.BinaryWrite(data);
}
 
B

bruce barker

try:

using(FileStream fs=new FileStream(compressedFileNm,FileMode.Open))
{
byte [] data=new Byte[fs.Length];
BinaryReader br=new BinaryReader(fs);
br.Read(data,0,data.Length);
br.Close();

Response.Clear();

Response.ContentType="application/x-zip-compressed";
Response.AppendHeader("Content-Disposition","filename="
+compressedFileNm);
Response.BinaryWrite(data);
}

or simpler

Response.Clear();

Response.ContentType="application/x-zip-compressed";

Response.AppendHeader("Content-Disposition","filename="+compressedFileNm);
Response.BinaryWrite(compressedFileNm);

-- bruce (sqlwork.com)



| Hi All, I am trying to allow clients to download zipped file from my
system
| using the code below. Apparently the file gets downloaded but when the
users
| try opening the file with WinZip they get problem saying
| Cannot open this file: it doesn't appear to be a valid archive. If you
| downloaded this file, try downloading the file again.
|
| When I open the compressed file on the server, its fine.
|
| Any clues?
|
| TIA
|
| using(FileStream fs=new FileStream(compressedFileNm,FileMode.Open))
| {
| byte [] data=new Byte[fs.Length];
| BinaryReader br=new BinaryReader(fs);
| br.Read(data,0,data.Length);
| br.Close();
|
| Response.ContentType="application/x-zip-compressed";
| Response.AppendHeader("Content-Disposition","filename="
| +compressedFileNm);
| Response.BinaryWrite(data);
| }
|
|
 
V

Vai2000

No luck. BTW in the second solution BinaryWrite expects bytes [] as
parameter instead of filename so that didn't compiled.

TIA
 
V

Vai2000

Found the solution:

Response.AddHeader ("Content-Length", data.Length.ToString());



Vai2000 said:
No luck. BTW in the second solution BinaryWrite expects bytes [] as
parameter instead of filename so that didn't compiled.

TIA

bruce barker said:
try:

using(FileStream fs=new FileStream(compressedFileNm,FileMode.Open))
{
byte [] data=new Byte[fs.Length];
BinaryReader br=new BinaryReader(fs);
br.Read(data,0,data.Length);
br.Close();

Response.Clear();

Response.ContentType="application/x-zip-compressed";
Response.AppendHeader("Content-Disposition","filename="
+compressedFileNm);
Response.BinaryWrite(data);
}

or simpler

Response.Clear();

Response.ContentType="application/x-zip-compressed";

Response.AppendHeader("Content-Disposition","filename="+compressedFileNm);
Response.BinaryWrite(compressedFileNm);

-- bruce (sqlwork.com)



| Hi All, I am trying to allow clients to download zipped file from my
system
| using the code below. Apparently the file gets downloaded but when the
users
| try opening the file with WinZip they get problem saying
| Cannot open this file: it doesn't appear to be a valid archive. If you
| downloaded this file, try downloading the file again.
|
| When I open the compressed file on the server, its fine.
|
| Any clues?
|
| TIA
|
| using(FileStream fs=new FileStream(compressedFileNm,FileMode.Open))
| {
| byte [] data=new Byte[fs.Length];
| BinaryReader br=new BinaryReader(fs);
| br.Read(data,0,data.Length);
| br.Close();
|
| Response.ContentType="application/x-zip-compressed";
| Response.AppendHeader("Content-Disposition","filename="
| +compressedFileNm);
| Response.BinaryWrite(data);
| }
|
|
 
Joined
Mar 31, 2008
Messages
2
Reaction score
0
Hi,
how did you solve your problem?
I am experiencing the same problem.

Thanks !
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top