Search code examples
c#compressionzipwinrar

Compressing Files With C# By Winrar


I never done this but I am develping a simple application and really need some help.

The scenario is that I have some excel files which are all name coded, I need to get the first 5 letters of each files and compress those together. Ex.

MARKS MARKS 2 MARKS 3

These all compress.

Is their any method to do this and zip with winrar.

Thanks


Solution

  • I agree IonicZip (now dotnetzip) is good. here is the sample of what you want to do

            string somepath = "D:\\ExcelFiles";
            string zippath = "D:\\ExcelFiles\\some.zip";
            string[] filenames =
            System.IO.Directory.GetFiles(somepath, "Mark*.xlsx", SearchOption.AllDirectories);
    
            using (ZipFile zip = new ZipFile())
            {
                foreach (String filename in filenames)
                {
    
                    ZipEntry e = zip.AddFile(filename, "");
    
                }
                zip.Save(zippath);
            }