Using the normal Windows file system, the ExtractToFile
method would be sufficient:
using (ZipArchive archive = new ZipArchive(uploadedFile.InputStream, ZipArchiveMode.Read, true))
{
foreach (var entry in archive.Entries.Where(x => x.Length > 0))
{
entry.ExtractToFile(Path.Combine(location, entry.Name));
}
}
Now that we are using Azure, this obviously needs to change as we are using blob storage.
How can this be done?
ZipArchiveEntry
class has an Open
method which returns a stream. What you could do is create a blob using that stream.
static void ZipArchiveTest()
{
storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("temp");
container.CreateIfNotExists();
var zipFile = @"D:\node\test2.zip";
using (FileStream fs = new FileStream(zipFile, FileMode.Open))
{
using (ZipArchive archive = new ZipArchive(fs))
{
var entries = archive.Entries;
foreach (var entry in entries)
{
CloudBlockBlob blob = container.GetBlockBlobReference(entry.FullName);
using (var stream = entry.Open())
{
blob.UploadFromStream(stream);
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With