0

Below is the code I am using.

 private static string ZipFile(string filename, DirectoryInfo oDir)
    {
        if (filename.IndexOf(".") > -1)
            filename = filename.Substring(0, filename.LastIndexOf('.'));


        string zipfile = String.Format("{0}\\{1}.zip", oDir.FullName, filename);


        using (FileStream oFS = new FileStream(zipfile, FileMode.OpenOrCreate))
        {

            using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream oZipIn = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(oFS))
            {
                oZipIn.Flush();
                oZipIn.IsStreamOwner = true;
                oZipIn.Finish();
            }
        }
        using (FileStream oFS = new FileStream(zipfile, FileMode.OpenOrCreate))
        {
            oFS.Seek(0, SeekOrigin.Begin);
            using (ICSharpCode.SharpZipLib.Zip.ZipFile oFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(oFS))
            {
                //oFile.IsEmbeddedArchive;
                oFile.BeginUpdate();
                Array.ForEach(oDir.GetFiles(), file =>
                            {
                                if (file.Name != filename + ".zip")
                                {
                                    oFile.Add(file.FullName, file.Name);
                                }
                            }
                        );

                oFile.CommitUpdate();
                oFile.Close();
            }
            if (oFS != null)
                oFS.Dispose();

        }
        return zipfile;
    }

The same code was working fine when I was using the old verison of SharpZiplib Version=0.86.0.518 But after upgrading the version to 1.4.1 getting error at this point of code oFile.BeginUpdate(); And with this update the framework also from 4.5 to 4.8 The error is : ICSharpCode.SharpZipLib.Zip.ZipException: Cannot update embedded/SFX archives" Is there any issue with the latest version of SharpZipLib or am I missing something here to change in my code. I looked into the library code and can see that this error is coming becasue IsEmbeddedArchive value is true. I have lots of questions here. Why IsEmbeddedArchive this is coming as true? I did not do any code change only updated the version so the same value should have passed preiously also, so how it was working on old version? Is there a way so that I can change IsEmbeddedArchive to false? What should I do to make it work?

I don't know what to try here. I just tried to use the old version of SharpZiplib Version=0.86.0.518 and it is working fine. But not with the 1.4.1

0 Answers0