Question

I have looked around quite abit and there does not seem to be any information on using sharpziplib to extract multiple zip files to the same directory. I am using telerik control RadUpload to upload two different zip folders and when uploaded they are automatically unzipped into a folder with the same name as the zip to the same directory.

For example: I have autocorrect.zip and entertainment.zip. Autocorrect extracts to a folder called "autocorrect" and entertainment extracts to a folder called "entertainment". Autocorrect is in the first box and entertainment in the second.

But in the extract folder only "entertainment" appears. Now I think this is because the way I current have the unzip method set up as it takes in the first value "autocorrect" and then it also takes"entertainment" as the first value afterwards therefore "autocorrect" is no longer listed to be extracted.

Here is my code for the unzip method if you believe other parts of my code would help please say and I'll post more:

public static void UnZip(string sourcePath, string targetPath)
{
    //Creates instance of fastzip from library ICSharpCode
    ICSharpCode.SharpZipLib.Zip.FastZip fz = new FastZip();
    //Extracts zip from sourcePath to target path which is chosen in the button click methods
    fz.ExtractZip(sourcePath, targetPath, "");
}

EDIT: Here is the button method which calls the unzip with the save path for the zip files and save path for the extracted zips (Forgot to say it works perfectly for one zip but not for multiple zips)

 protected void SubmitButton_Click(object sender, EventArgs e)
    {
        //Gets the name of the file being uploaded
        foreach (UploadedFile file in RadUpload1.UploadedFiles)
        {
            fileName = file.GetName();
        }
        //Path where zip files are uploaded
        String savePath = @"C:\Users\James\Documents\Visual Studio 2012\WebSites\CourseImport\CourseTelerik\";
        //Adds name of uploaded file onto end of saved path
        savePath += fileName;
        //Path where the extracted files from the uploaded zip are placed
        String unZipPath = @"C:\Users\James\Documents\Visual Studio 2012\WebSites\CourseImport\CourseTelerikExtract\";
        unZipPath += fileName;
        //Runs unzipping method
        UnZip(savePath, unZipPath);
Was it helpful?

Solution

Your method was just getting the last fileName and calling the UnZip only once

So the below code will call with the total number of fileName available in RadUpload1.UploadedFiles

protected void SubmitButton_Click(object sender, EventArgs e)
{

String savePath = @"C:\Users\James\Documents\Visual Studio 2012\WebSites\CourseImport\CourseTelerik\";

String unZipPath = @"C:\Users\James\Documents\Visual Studio 2012\WebSites\CourseImport\CourseTelerikExtract\";


foreach (UploadedFile file in RadUpload1.UploadedFiles)
{
   string fileName = file.GetName();

   UnZip((savePath + fileName),  (unZipPath + fileName) );
}

}

OTHER TIPS

check this out and try to use the example this::

http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx

check this out and try to use the example this: Unpack a Zip with full control over the operation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top