This project is read-only.

Unable to open or Read .zip file from ASP.NET that includes password protected file

Apr 25, 2009 at 7:11 AM
  when i m using simple this works fine but when i assign paasword  for the particaular file its created problem to read.
  at the time of read i am getting this error message which is given below:

You cannot change the encryption method on encrypted entries read from archives.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: You cannot change the encryption method on encrypted entries read from archives.

Source Error: 

Line 82:             using (ZipFile zip = ZipFile.Read(abFileContent))Line 83:             {Line 84:                 

using Ionic.Zip;

 byte[] abFileContent = new Byte[fileUpload1.PostedFile.ContentLength];
 fileUpload1.PostedFile.InputStream.Read(abFileContent, 0, fileUpload1.PostedFile.ContentLength);

 using (ZipFile zip = ZipFile.Read(abFileContent))
                bool IsfileExists = false;
                foreach (ZipEntry zipe in zip.Entries)
                    if (zipe.FileName.Equals(string.Format("{0}.xml", XMLFileName)))
                        IsfileExists = true;
                        if (!string.IsNullOrEmpty(password))
                            zipe.ExtractWithPassword(m_FilePath, password);
                            zipe.Extract(m_FilePath, true);
                if (!IsfileExists)
                    throw new FileNotFoundException(string.Format("{0}.xml file not found in source zip file", XMLFileName));

The code of ziping file with password

using Ionic.Zip;


            System.Web.HttpContext c = System.Web.HttpContext.Current;
            String ReadmeText = String.Format(obj.ReadmeContents, Environment.NewLine,
            string zipfileName = "";
            System.Web.HttpContext.Current.Response.ContentType = "application/zip";
            System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "filename=" + zipfileName);
         using (Stream str = new MemoryStream())
                using (ZipFile zip = new ZipFile())
                   ZipEntry e = zip.AddFileStream(string.Format("{0}.xml", XmlFileName), "", str);
                   if (!string.IsNullOrEmpty(obj.ZipPassword))
                       e.Encryption = EncryptionAlgorithm.WinZipAes128;
                       e.Password = ZipPassword;
                    zip.AddFileFromString(string.Format("{0}.txt", ReadmeFileName), "", ReadmeText);
                    zip.Comment = string.Format("{0}", ZipFileComment);

Apr 28, 2009 at 6:35 PM
Edited Apr 28, 2009 at 6:37 PM
Hmm, that's not good.
Did you post a work item on this?

Is this the same as