Reputation: 227
How do you convert a physical zip file to System.IO.Stream object?
I tried -
System.IO.Stream stream = File.ReadAllBytes(Path + "\\" + "ZipFile.zip");
StreamReader stream = new StreamReader(Path + "\\" + "ZipFile.zip");
System.IO.Stream stream = new FileStream(Path + "\\" + "ZipFile.zip", FileMode.Open); stream.Close();
None of them seems to be working.
When trying to read the stream it either says the stream is not readable
or the file seems corrupt at the destination and cannot be unzipped
Upvotes: 0
Views: 3224
Reputation: 690
Try this code.For using this code you have to download dotnetzip-ionic.dll
using Ionic.Zip;
using Ionic.Crc;
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
using (ZipFile zip = ZipFile.Read(ZipPath))
{
foreach (ZipEntry entry in zip)
{
CrcCalculatorStream reader = entry.OpenReader();
MemoryStream memstream = new MemoryStream();
reader.CopyTo(memstream);
byte[] bytes = memstream.ToArray();
System.IO.Stream stream = new System.IO.MemoryStream(bytes);
}
}
}
Upvotes: 1
Reputation: 36092
Take a look at ZipInputStream
from SharpZipLib: https://github.com/icsharpcode/SharpZipLib
via https://stackoverflow.com/a/593036/301152
Upvotes: 0
Reputation: 100545
byte[]
to Stream
)... So not sure how you get runtime error here.StreamReader
is not a stream - not sure what conversion you expect here.Upvotes: 1