Get all file names when unzip file

Binumon George 161 Reputation points
2021-11-24T03:15:28.703+00:00

Hi All,
I am zipping one folder containing 10 files like abc.txt, pqr.docx,xyz.txt, etc using c#. Now I want to unzip that zip file. But when I Unzip I want to get all files' names in a string with a comma-separated value. How it's possible using c#?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,977 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Petrus 【KIM】 451 Reputation points
    2021-11-24T05:28:29.533+00:00
    public string GetFilenamesInZip(string sZipFileName)
    {
        string sFileNames = string.Empty;
    
        using (ZipArchive oArchive = ZipFile.OpenRead(sZipFileName))
        {
            foreach (var vEntryItem in oArchive.Entries)
            {
                sFileNames += (vEntryItem + ",");
            }
        }
        if (sFileNames != string.Empty)
            sFileNames = sFileNames.Substring(0, sFileNames.Length - 1);
        return sFileNames;
    }
    
    No comments