Zip File Download Error!!!

  • Thread starter Thread starter Vai2000
  • Start date Start date
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);
}
 
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);
| }
|
|
 
No luck. BTW in the second solution BinaryWrite expects bytes [] as
parameter instead of filename so that didn't compiled.

TIA
 
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);
| }
|
|
 
Back
Top