This is a migrated thread and some comments may be shown as answers.

Read Textfiles from zip archive

1 Answer 33 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 15 Jan 2018, 08:11 PM

How can I read Textfiles into string or into array without extract to temporary file before?

If not possible:

is there any c# example to read Textfiles to string from zip archive.

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 18 Jan 2018, 05:58 PM
Hello Andreas,

You can achieve that by opening the archive file and reading its entries. When you need to get a string from the entry's stream, you can use the StreamReader class. Here is a simple example:

using (Stream stream = File.Open("test.zip", FileMode.Open))
{
    using (ZipArchive archive = new ZipArchive(stream))
    {
        foreach (ZipArchiveEntry entry in archive.Entries)
        {
            using (StreamReader reader = new StreamReader(entry.Open(), Encoding.UTF8))
            {
                string content = reader.ReadToEnd();
            }
        }
    }
}

Hope this is helpful.

Regards,
Tanya
Progress Telerik

Tags
ZipLibrary
Asked by
Andreas
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or