Add a zipFile in a ZipFile.

Feb 4, 2010 at 5:02 PM

I have a folder which contains a text file and a zip file.

I am using this code to add it but unable to reverse engineer it.

 

 

foreach (string file in io.Directory.GetFiles(dir))
                {
                    if (file.EndsWith(".txt"))
                    {
                        zf.AddFile(file);
                    }
                    else
                    {
                        if (ZipFile.IsZipFile(file) && (io.Path.GetExtension(file).EndsWith(".zip")))
                        {

                            byte[] arr = io.File.ReadAllBytes(file););

                            zf.AddEntry("Un", arr);
                            
                        }

}

 

When reverse engineering it:

 

ZipFile temp = ZipFile.Read("t.zip")

foreach (ZipEntry e in temp.Entries)
                {
                    //e.Password = "OmSaiSreeSaiJayaJayaSai";
                    io.MemoryStream ms = new System.IO.MemoryStream();
                    e.Extract(ms);
                    if (e.FileName.EndsWith(".txt"))
                    {
                    }
                    else
                    {

                        byte[] arr = ms.ToArray();
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
                        ZipFile zf3 = ZipFile.Read(ms);
                        zf3.Save(@"c:\temp\test" + i.ToString() + ".zip"); --> Its throwing exception here
                    }
                }

Please let me know if you have any suggestions.

Thanks

 

 

Coordinator
Feb 4, 2010 at 11:33 PM

You said you are getting an exception, but you didn't specify which exception.

Getting the full exception stacktrace is a good first step towards understanding the problem.