0

So at the moment i am attempting to write to a password protected .dat file which is within a zip folder.

The code below attempts to do that but when i try to open that the file in the zip folder (with the correct password and all) it comes up with the following error: "windows cannot complete the extraction. The destination file cannot be created".

Any help would be appreciated.

Thank you

using (FileStream zipToOpen = new FileStream(@"System.zip", FileMode.Open)) {
 // Opening zip file containing .dat files
    using (ZipOutputStream OutStream = new ZipOutputStream(zipToOpen)) {
        OutStream.Password = "Password";
        OutStream.PutNextEntry("system.dat"); // Name of file trying to write to
        MessageBox.Show(OutStream.CanWrite.ToString());//verifys that the file is writable
        using (BinaryWriter b = new BinaryWriter(OutStream)) {
            b.Write("hi");
        }
    }
}
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
  • check this - http://stackoverflow.com/questions/24982165/auto-extract-a-zip-file – keerti Jan 03 '17 at 10:37
  • Where did the zip file come from? – keerti Jan 03 '17 at 10:39
  • Thanks for that, but i want to write straight to the .dat file without extracting it. I've managed to find a way to read it but finding a way to write to it is much more difficult it seems. – Danieliqbal Jan 03 '17 at 10:41
  • I created the zip file previously and password protected it. Now my aim is to write to it without extracting it. – Danieliqbal Jan 03 '17 at 10:42

0 Answers0