SharpDevelop Community

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

cannot find central directory - ICSharpCode.SharpZipLib

Last post 05-31-2011 2:21 AM by michealmess. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-19-2011 2:48 AM

    cannot find central directory - ICSharpCode.SharpZipLib

    Sometime clients get the message "cannot find central directory" when trying to open (uncompress) files in my application.

    It doesnt happen all the time. It only happens about 1% of the time. I also cannt open the file with Winzip or Winrar.

     

    I am using version 0.85.4.369 of ICSharpCode.SharpZipLib

  • 05-27-2011 7:57 AM In reply to

    Re: cannot find central directory - ICSharpCode.SharpZipLib

    Hi,

    From the fact that "also cannot open the file with Winzip or Winrar" this implies that the file is damaged.

    You have not told us anything about the origin or transportation of these files. Can you tell us that?

    Can you expand on the background to this issue?

    Also, 0.86.0 is the current version, but I'll be the first to admit that upgrading is unlikely to solve this problem :-)

    If you are FTPing the files, maybe ascii translation is occurring sometimes.

    Regards,
    David

  • 05-27-2011 8:10 AM In reply to

    Re: cannot find central directory - ICSharpCode.SharpZipLib

    I am using the same classes to save the file. So i create the file. This doenst happen all the time. Only about 1% of the time. By those clients are losing their files as its damaged. Its very hard to replicate.

     

    Could anti - virus software be causing this?

  • 05-27-2011 8:17 AM In reply to

    Re: cannot find central directory - ICSharpCode.SharpZipLib

    Upgrading to 0.86.0 will not hurt, particularly as you are using a cut two versions ago.

    Also can you post your create code?

    A bug was fixed in 0.86.0 that used to cause corrupt zips with zero-byte files and ZipOutputStream, but it resulted in a different error message in unpacking AFAIK. Have a look at the release history.

    You should add some code into the pack code to do a test unpack of your newly-created zipfile (discarding the output). Save the output of any failures for our inspection if you can.

  • 05-27-2011 8:28 AM In reply to

    Re: cannot find central directory - ICSharpCode.SharpZipLib

    This is the save code. Thanks for your help!

     

      Dim ZipStream As ZipOutputStream = Nothing
                BackupFileBeforeSave()
                Try
                    System.IO.File.Delete(Me.EMFileName)
                    ZipStream = New ZipOutputStream(File.Create(Me.EMFileName))
                Catch ex As Exception
                    CopyBackupFileBackToOriginalLocation()
                    Throw New Exception(Environment.NewLine + "- Error creating zip file " + ex.Message)
                End Try

                'Dim ZipStream As New ZipOutputStream(File.Create(Me.EMFileName))

                'Password  ===========================================
                'Checks the Password Option is OFF or ON
                If (XMLUtility.PasswordOptionSet(EstateMaster.Services.DM.DMServicesUtility.AppConfigPath)) AndAlso Me.ZipFilePassword <> String.Empty Then
                    ZipStream.Password = Me.ZipFilePassword

                    'specify a comment which will identify that it is paasword protected at the time of opening.
                    ZipStream.SetComment(EMConstants.ZipFileComment)
                End If
                'Password  ===========================================

                REM Compression Level: 0-9
                REM 0: no(Compression)
                REM 9: maximum compression
                ZipStream.SetLevel(9)
                'Dim strFile As String
                'Dim strTempDataFile As String
                'Looping thru the collection of files in the folder
                For Each FileName As String In FilesToBeZipped
                    'strFile = strFileName & strgFileExtension
                    'For Each DataFileFielName As String In FileNamesToBeZipped
                    'Checking for only xml and xls files
                    ' If (FileName.ToLower() = DataFileFielName.ToLower()) Then
                    'If (strTempDataFile.Length > 0) Then
                    Dim strmFile As FileStream = File.OpenRead(FileName)
                    Dim abyBuffer(CInt(strmFile.Length - 1)) As Byte

                    strmFile.Read(abyBuffer, 0, abyBuffer.Length)
                    'Dim objZipEntry As ZipEntry = New ZipEntry(strFile)
                    Dim objZipEntry As ZipEntry = New ZipEntry(FileName.Substring(FileName.LastIndexOf("\") + 1))

                    objZipEntry.DateTime = DateTime.Now
                    objZipEntry.Size = strmFile.Length
                    strmFile.Close()
                    strmFile.Dispose()
                    strmFile = Nothing
                    ZipStream.PutNextEntry(objZipEntry)
                    ZipStream.Write(abyBuffer, 0, abyBuffer.Length)
                    objZipEntry = Nothing
                    'End If
                    'Next
                Next
                ZipStream.Finish()
                ZipStream.Close()
                ZipStream = Nothing

  • 05-29-2011 12:51 AM In reply to

    Re: cannot find central directory - ICSharpCode.SharpZipLib

    Thanks for posting the code. It looks fine.

    Don't add any code that references the CRC, there is an issue around that still unfixed.

    All I can suggest is same as in my last post - upgrade to 0.86.0 - the one you are using is way old. Also add a check on the output file to see if it is okay. Have a look at the new code samples in the wiki - all with VB samples now :-)

    If you are worried about the extra time taken by the test unpack, reduce your compression level - you'll often find you can get away with much lower levels e.g. 3 for great increase in speed with little decrease in compression.

    Are you delivering them via IIS? Internet Explorer appears to sometimes give grief from the content type header. Check this post http://community.sharpdevelop.net/forums/t/10467.aspx

    Regards,
    David

  • 05-31-2011 2:21 AM In reply to

    Re: cannot find central directory - ICSharpCode.SharpZipLib

    Thanks for your assistance. No IIS.

     

    I will upgrade to latest version

     

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