11
Answers

Problem unziping multiple files with ICSharpCode.SharpZipLib.Zip;

thiago costa

thiago costa

13y
6.6k
1
Hello there guys.
I am having problems extracting files out of a ZIP file.. well, it kind of works, but not the way I wished, and my future plan involves this procedure..

This is the problem I am having:
When I execute the command to unzip the file "update.zip", it will not extract ALL files inside the "update.zip" ... It will ONLY extract ONE !!!! NOT ALL !

I don't get it... It makes no sense to me, I'm so confused...

I am using a third party reference "ICSharpCode.SharpZipLib.Zip;" ... I think it is kind of pupular.

This is the CLASS I am using:


 namespace SelfUpdate
{
class ZipHelp
{
/// Zip a file
public static void Zip(string SrcFile, string DstFile, int BufferSize)
{
FileStream fileStreamIn = new FileStream(SrcFile, FileMode.Open, FileAccess.Read);
FileStream fileStreamOut = new FileStream(DstFile, FileMode.Create, FileAccess.Write);
ZipOutputStream zipOutStream = new ZipOutputStream(fileStreamOut);

byte[] buffer = new byte[BufferSize];

ZipEntry entry = new ZipEntry(Path.GetFileName(SrcFile));
zipOutStream.PutNextEntry(entry);

int size;
do
{
size = fileStreamIn.Read(buffer, 0, buffer.Length);
zipOutStream.Write(buffer, 0, size);
} while (size > 0);

zipOutStream.Close();
fileStreamOut.Close();
fileStreamIn.Close();
}

public static void UnZip(string SrcFile, string DstFile, int BufferSize)
{
FileStream fileStreamIn = new FileStream(SrcFile, FileMode.Open, FileAccess.Read);
ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
ZipEntry entry = zipInStream.GetNextEntry();
FileStream fileStreamOut = new FileStream(DstFile + "" + entry.Name, FileMode.Create, FileAccess.Write);

int size;
byte[] buffer = new byte[BufferSize];
do
{
size = zipInStream.Read(buffer, 0, buffer.Length);
fileStreamOut.Write(buffer, 0, size);
} while (size > 0);

zipInStream.Close();
fileStreamOut.Close();
fileStreamIn.Close();
}
}
}



This is the command inside of form1


   private void button1_Click(object sender, EventArgs e)
{

label1.Text = ("Downloading new version");
try
{

WebClient Client = new WebClient();


Client.DownloadFile("http://98.118.57.8/anti/update.zip", "update.zip");
Client.DownloadProgressChanged +=new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);


label1.Text = ("Please wait, updating...");

Thread th = new Thread(new ThreadStart(UnZip));
th.Start();

label1.Text = ("Update Installed");


}
catch
{
MessageBox.Show("Server is offline, can not download file");
}

}

private void UnZip()
{

ZipHelp.UnZip(textBoxFileName.Text, Path.GetDirectoryName(textBoxFileName.Text), 4096);

}

Well, I think with that command, it should download ALL files inside the assigned zip file, which in this case is the update.zip
But if there are 10 files inside the update.zip, it will only extract 1 (one)

I don't understand



Thanks guys...





-----EDIT-------

I really don't understand this issue... Shouldn't it extract ALL files inside of ZIP ? ...
Also, do you guys have a better method to do this? ... I don't like how I am doing it...

Maybe a different reference will be better instead of csharplib ?

Answers (11)