You are here: Blog
Menu
Categories
.NET
DotNetNuke
ECO
General
UI
Archive
August, 2014 (1)
September, 2013 (1)
February, 2010 (2)
October, 2008 (2)
September, 2008 (1)
July, 2008 (2)
June, 2008 (1)
April, 2008 (3)
February, 2008 (1)
December, 2007 (1)
October, 2007 (2)
June, 2007 (2)
March, 2007 (1)
January, 2007 (1)
December, 2006 (3)
Search
Software development matters
Feb 8

Written by: Oleg Zhukov
2/8/2010 10:10 PM

The other day I needed to unzip a bunch of zip-archives, modify the unzipped content and zip them back again. Since I'm lazy (as every developer should be) I decided to write a tool that would do all the work for me.

After googling around I found several ways of handling zip archives. First of them I tried was the System.IO.Packaging namespace classes available in .NET 3.0. But disappointment came soon when it simply failed to unzip my archives probably due to some zip format incompatibility.

Well-known #ziplib turned out to be under GPL, and I also heard it's less usable than its main competitor DotNetZip.

With DotNetZip i did my job in several minutes:

private void ProcessMMCSECOfile(string mmcsecoFileName)
{
    using (ZipFile mmcseco = ZipFile.Read(mmcsecoFileName))
    {
        mmcseco.CompressionLevel = CompressionLevel.None;
        string newCodeModelContents = ChangeEncoding(
                GetContents(mmcseco, "codemodel.xml"));
        string newDiagramsContents = ChangeEncoding(
                GetContents(mmcseco, "diagrams.xml"));
        mmcseco.RemoveEntry("diagrams.xml");
        mmcseco.RemoveEntry("codemodel.xml");
        mmcseco.AddEntry("diagrams.xml", newDiagramsContents);
        mmcseco.AddEntry("codemodel.xml", newCodeModelContents);
        mmcseco.Save();
    }
    processedFilesCount++;
}

string GetContents(ZipFile zipFile, string archivedFileName)
{
    using (Stream st = zipFile[archivedFileName].OpenReader())
    {
        using (StreamReader reader = new StreamReader(st,
            Encoding.GetEncoding(correctEncodingTxtBox.Text)))
        {
            return reader.ReadToEnd();
        }
    }
}

Tags:
Copyright 2007-2016 by Oleg Zhukov Terms Of UsePrivacy Statement