I've the below code, that create
a new zip file, then add entry
to this file with NoCompression
i.e. ZERO compression ratio
then try to read this entry as normal text.
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
using (FileStream zipToOpen = new FileStream(@"d:\release.zip", FileMode.Create))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
{
ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt", CompressionLevel.NoCompression);
using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
{
writer.WriteLine("Information about this package.");
writer.WriteLine("========================");
}
}
}
string text = System.IO.File.ReadAllText(@"d:\release.zip\Readme.txt");
Console.WriteLine("Contents of WriteText.txt = {0}", text);
}
}
}
Both the zip file and its entry are created, and I can access them from the windows explorer, but once the code try to read it, it get the below error:
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path 'd:\release.zip\Readme.txt'. at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions opti ons, FileStream parent) at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions o ptions, FileStream parent) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.File.InternalReadAllText(String path, Encoding encoding)
at System.IO.File.ReadAllText(String path) at ConsoleApplication.Program.Main(String[] args)