Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I have a problem when trying to extract the zip file.
my code is below.
C#
FileStream writeStream = new FileStream("test.csv.zip", FileMode.Create);
                int Length = 2048;
                int i = (int)fileSize / 2048 + 1;
                int j = 0;
                Byte[] buffer = new Byte[Length];
                int bytesRead = responseStream.Read(buffer, 0, Length);
                while (bytesRead > 0)
                {
                    writeStream.Write(buffer, 0, bytesRead);
                    bytesRead = responseStream.Read(buffer, 0, Length);
                }
                writeStream.Close();
                response.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            param par = p;
            string url = string.Empty; 
            string TimeLeft = string.Empty;
            string writeLine = string.Empty;
            DateTime date = DateTime.Now.AddDays(par.days);
            string find = date.Month.ToString() + "/" + date.Day.ToString() + "/" + date.Year.ToString();
            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read("test.csv.zip"))
            {
                zip.ExtractAll("temp", Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                
            }

Error:- bad read of entry test.csv from compressed archive.

Although zip file have data If I extract manually I get the data but with this code I am getting error .

Can you please tell me where I did mistake or the solution.

Thanks and Regards!
Kuldeep Dwivedi
Posted
Updated 5-Jan-12 2:34am
v2

1 solution

Since the source of the problem is unclear, try to identify that first:

  • is it the zip file?
  • is it your wget code?
  • is it the file system caching (stored as file and immediately read again may fall into file system caching problems)?
  • is it your unzip call?
  • ...?



  1. store the zip file to the file system and extract it by the file explorer, ZIP.exe, RAR,exe, 7z.exe, or any other unzipper
  2. if 1. was successful, the ionic unzipper call seems to be problematic
  3. if 1. was unsuccessful, either the file is corrupt or your hand crafted wget is broken
  4. try to acquire the file by other means, outside of your program (wget, ftp, ...) and unzip it with outside as well (see 2.)


BTW: you provide only half of the code. No chance to check what might be wrong with your wget code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900