views:

111

answers:

1

I've downloaded ICSharpCode.SharpZipLib and DotNetZip. I'm zipping over 100 files at a time varying a meg to 4 megs. When I use ICSharpCode I get a 'ContextSwitchDeadlock' error. DotNetZip fails on the finalizing of the file every time.

Also, I'm working on sharepoint folders (mapped to my local drive)

private bool zipall()
//ICSharpCode
{
    int i = 0;
    progressBarzipping.Minimum = 0;
    progressBarzipping.Maximum = listBoxfiles.Items.Count;
    ZipOutputStream zipOut = new ZipOutputStream(File.Create(textBoxDropPath.Text + "\\" + textBoxZipFileName.Text + ".zip"));
    foreach (string fName in listBoxfiles.Items)
    {
        try
        {
            FileInfo fi = new FileInfo(fName);
            ZipEntry entry = new ZipEntry(fi.Name);
            FileStream sReader = File.OpenRead(fName);
            byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
            sReader.Read(buff, 0, (int)sReader.Length);
            entry.DateTime = fi.LastWriteTime;
            entry.Size = sReader.Length;
            sReader.Close();
            zipOut.PutNextEntry(entry);
            zipOut.Write(buff, 0, buff.Length);
        }
        catch
        {
            MessageBox.Show("Zip Failed");
            zipOut.Finish();
            zipOut.Close();
            progressBarzipping.Value = 0;
            return false;
        }
        i++;
        progressBarzipping.Value = i;
    }
    zipOut.Finish();
    zipOut.Close();
    MessageBox.Show("Zip Complete");
    progressBarzipping.Value = 0;
    return true;

}

//Not sure but I think this was my DotNetZip approach
//using (ZipFile zip = new ZipFile())
//  {
//     foreach(string file in listboxFiles.Items)
//       {
//         zip.AddFile(file);
//       }      
//  zip.Save(PathToNewZip);
//  }
A: 

You didn't provide the exception. When using DotNetZip, I guess the problem might be with the sharepoint mapped drive. DotNetZip normally will save the zip as a temp file, then rename it. Maybe this isn't working because of sharepoint. If that's the case, try opening a filestream and saving it to that stream. This avoids the rename operation.

progressBarzipping.Minimum = 0; 
progressBarzipping.Maximum = listBoxfiles.Items.Count;
using (Stream fs = new FileStream(PathToNewZip, FileMode.Create, FileAccess.Write))
{
    using (ZipFile zip = new ZipFile()) 
    { 
       zip.AddFiles(listboxFiles.Items);

       // do the progress bar: 
       zip.SaveProgress += (sender, e) => {
          if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry) {
             progressBarzipping.PerformStep();
          }
       };

       zip.Save(fs); 
    }
} 
Cheeso
I'll give it a try.
Chris