File loses password protection after zipfile update

Jul 5, 2009 at 2:53 PM
Edited Jul 5, 2009 at 2:56 PM

With  version 1.8.4.5. of the Mobile the DotNetZip  library I have a question (compact Framework 3.5). When I update a File in a password protected Zip. Then de updated file itself in the Zip is not password protected anymore (w.a.w. I can extract it without PW), While the rest of the files still have password protection. How can I set password protection on the file I update?

here the code I used:

Dim ZipToUpdate As String = "\Program Files\Shell\Zipfile.dat"
Dim FileToUpdate As String = "\Storage Card\Shell\File.txt"
Using MyZip As ZipFile = ZipFile.Read(ZipToUpdate)
MyZip.UpdateFile(FileToUpdate, "")
      MyZip.Password = "12345678"
      MyZip.Save()
End Using

Coordinator
Jul 5, 2009 at 3:48 PM

Set the Password property before you call UpdateFile(). 

Dim ZipToUpdate As String = "\Program Files\Shell\Zipfile.dat"
Dim FileToUpdate As String = "\Storage Card\Shell\File.txt"
Using MyZip As ZipFile = ZipFile.Read(ZipToUpdate)
    MyZip.Password = "12345678"
    MyZip.UpdateFile(FileToUpdate, "")
    MyZip.Save()
End Using

Some additional info - In your code, after ZipFile.Read(), you call UpdateFile(). At this point there is no Password property set on the MyZip variable. (in other words, the PAssword is Nothing) So, no password is used when adding/updating any new entries, as you do with UpdateFile(). If you later set a password on the ZipFile instance, it does not apply to all entries in the zip file. It applies only to entries subsequently added or updated. In your code, it applies to no entries, because you don't add or update any entries after setting the Password.

For more on this, see the doc for the ZipFile.Password property.

Jul 5, 2009 at 8:13 PM

Hi

Great thanks for your quick response….
And Yes that did it, Now it Works like a charm.

PS. Can’t open HTML doc, left pane is visible right one  not..

Thanks again!

Mike

Coordinator
Jul 5, 2009 at 8:34 PM

Mike,

From the home page:

I cannot view the CHM documentation. The error is: "This program cannot display the webpage." or, "The address is invalid." Is there an error with the chm file?
No, there is no problem with the CHM file. You have likely encountered a problem with Windows protection of files downloaded from less trusted locations. To view the chm file, within Windows Explorer, right-click on the CHM file, select properties, and Unblock it (button in lower part of properties window).

Jul 5, 2009 at 9:57 PM

Cheeso,

Sorry, overlookt on the home page, was to bussy reading the discussions..
And
I Never noticed the UnBlock button there. UnBlocked the file and now I Can read it…

Many thanks again.

Mike

"Still one hour to go in Sunday, do you never sleep ;-)"