Pregunta

I'm trying to create a small program that regularly downloads a ZIP archive (a GTFS feed), extracts the files and loads the data into a database. The files should be stored in Isolated Storage.

However, I cannot find a way to extract the ZIP archive. There are multiple built-in classes that handle decompression, but they either take directory/file names as arguments or cannot handle multiple files/directories.

What am I missing? How do we extract a ZIP file in Isolated Storage into a directory there (without using third party libraries)?

¿Fue útil?

Solución

Open the zip archive and enumerate all the entries. Open each entry which gives you a stream then copy the content of that entry to an isolated storage stream:

using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
    foreach (ZipArchiveEntry entry in archive.Entries)
    {
        using (Stream zipStream = entry.Open())
        using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(entry.Name, FileMode.CreateNew, isoStore))
        {
            // copy from zipStream to isoStream
        }
    }
} 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top