SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Create new Zip file from existing zip, getting error

Last post 11-17-2016 10:43 PM by rxdevarasett. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 11-17-2016 10:43 PM

    Create new Zip file from existing zip, getting error

    Hello

    I am working on Creating a new zip file from existing zip file. I am using SharpZipLib version 0.86.0.518

    I need to encrypt and set password to the new zip file.

    I reviewed previous user forums and created a small console application. During testing we are getting the following error.

    Exception message: {"size was 0, but I expected 656"}

    Stack Trace:

       at ICSharpCode.SharpZipLib.Zip.ZipOutputStream.CloseEntry()
       at ConsoleApplication1.Class1.DoRebuildFile(String pArchivePath) in c:\Delete\Console\ConsoleApplication1\Class1.cs:line 39
       at ConsoleApplication1.Class1.test() in c:\Delete\Console\ConsoleApplication1\Class1.cs:line 23
       at ConsoleApplication1.Program.Main(String[ args) in c:\Delete\Console\ConsoleApplication1\Program.cs:line 15
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[ args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

     

    Source code:

    this.DoRebuildFile();

            public void DoRebuildFile()
            {
                using (ZipInputStream zip = new ZipInputStream(File.OpenRead("c:\\delete\\Inbound\\20160104.zip")))
                {
                    ZipEntry entry;
                    using (ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create("c:\\delete\\Archive\\20160104.zip")))
                    {
                       // zipOutputStream.Password = "test123";

                        while ((entry = zip.GetNextEntry()) != null)
                        {
                            zipOutputStream.PutNextEntry(this.CloneZipEntry(entry));
                            zipOutputStream.CloseEntry();
                        }
                    }
                }
            }

            private ZipEntry CloneZipEntry(ZipEntry curEntry)
            {
                ZipEntry newEntry = new ZipEntry(curEntry.Name);
                //newEntry.AESKeySize = 256;
                newEntry.DosTime = curEntry.DosTime;
                newEntry.CompressionMethod = curEntry.CompressionMethod;
                newEntry.Comment = curEntry.Comment;
                newEntry.Size = curEntry.Size;
                //newEntry.ExternalFileAttributes = curEntry.ExternalFileAttributes;
                newEntry.Flags = curEntry.Flags;
                if (curEntry.ExtraData != null)
                {
                    newEntry.ExtraData = new byte[curEntry.ExtraData.Length];
                    Array.Copy(curEntry.ExtraData, 0, newEntry.ExtraData, 0, curEntry.ExtraData.Length);
                }
                return newEntry;
            }

    I appreciate your great help. Thanks.

Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.