End of Central Directory record could not be found

后端 未结 10 1852
温柔的废话
温柔的废话 2020-11-29 10:39

I am downloading a zip file using c# program and I get the error

at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()
   at System.IO.Compression         


        
10条回答
  •  醉梦人生
    2020-11-29 11:20

    I have the same problem, but in my case the problem is with the compression part and not with the decompression.

    During the compression I need use the "Using" statament with the Stream and the ZipArchive objects too. The "Using" statament will Close the archive properly and I can decompress it without any problem.

    The working code in my case in VB.Net:

    Using zipSteramToCreate As New MemoryStream()
        Using archive As New ZipArchive(zipSteramToCreate, ZipArchiveMode.Create)
            ' Add entry...
        End Using
    
        ' Return the zip byte array for example:
        Return zipSteramToCreate.ToArray
    End Using
    

提交回复
热议问题