-->

unable to get multiple entries in SelectEntries of

2019-09-19 03:43发布

问题:

I'm trying to use DotNetZipLib-DevKit-v1.9 in my MVC3 Project to extract the files to a specific folder.

What i want is -- How to add multiple entries in zip.SelectEntries method.

Here is my code in controller action:

public ActionResult ExtractZip(string fileName, HttpPostedFileBase fileData)
        {
            string zipToUnpack = @"C:\Users\Public\Pictures\Sample Pictures\images.zip";
            string unpackDirectory = System.IO.Path.GetTempPath();

            using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
            {
                // here, we extract every entry, but we could extract conditionally
                // based on entry name, size, date, checkbox status, etc.  
                var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;");//This shows `0` items in collections

                foreach (var item in collections)
                {
                    item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
                }
            }
            return Json(true);
        }

In this line var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;"); if i specify only single extension ,it works fine

ex: var collections = zip1.SelectEntries("name=*.gif"); this works good

I've also seen SelectEntries method here, but it doesn't help though

How to add multiple entries ?

回答1:

Finally i could answer my own question.

Inorder to select multiple entries we need to use OR and to select multiple entries use the following code:

var collections = zip1.SelectEntries("(name=*.jpg) OR (name=*.jpeg) OR (name=*.png) OR (name=*.gif)");

foreach (var item in collections)
{
    item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}