With code coming from your demo's I get:
Compiler Error Message: BC30517: Overload resolution failed because no 'New' is accessible.
Source Error:
|
What am I doing wrong?
Marc
2 Answers, 1 is accepted
Hi Marc,
Thank you for reaching out. The error you're seeing is caused by a breaking change introduced in RadZipLibrary 2024 Q1. Starting from that version, the ZipArchive constructors were made obsolete and are no longer accessible. Full details are available here: Backward Compatibility - RadZipLibrary.
How to fix:
Replace the constructor call:
Using archive As New ZipArchive(memStream, ZipArchiveMode.Create, True, Nothing)With the new static factory method:
Using archive As ZipArchive = ZipArchive.Create(memStream)Do the same for any other place where you instantiate a ZipArchive — use ZipArchive.Create() for writing, ZipArchive.Read() for reading, or ZipArchive.Update() for updating existing archives.
Also, could you let us know which specific demo page is still erroring out for you? All ZipLibrary demos have been updated and should be working correctly now — for example: https://demos.telerik.com/aspnet-ajax/ziplibrary/examples/overview/defaultcs.aspx. If you are still seeing an error on a particular demo, we'd like to investigate further.
Regards,
Rumen
Progress Telerik
Thanks for your support.
I found the bespoken information en code snippet here:
https://www.telerik.com/products/aspnet-ajax/documentation/knowledge-base/ziplibrary-download-multiple-files-in-a-single-archive
Hi Rumen,
When creating the ZIP and sending it to the client we get the following message:
Hi Marc,
Thank you for the detailed report! We identified two issues in the KB article code that were causing the corrupt archive.
Issue 1: Obsolete Constructor (2024 Q1+)
Starting with the 2024 Q1 release, the ZipArchive constructors were made obsolete. Replace:
Using archive As New ZipArchive(memStream, ZipArchiveMode.Create, True, Nothing)With the new static factory method:
Using archive As ZipArchive = ZipArchive.Create(memStream)Issue 2: Incorrect entry/writer disposal pattern (the real cause of the 0-byte entries)
Even after switching to the new API, the archive was still corrupt because the BinaryWriter was wrapped in a Using block while the ZipArchiveEntry was not. This causes the entry stream to close before the entry is finalized, resulting in 0-byte entries.
The correct pattern — matching our working demo — is to wrap the entry in Using, call writer.Flush(), and not wrap the BinaryWriter in Using:
' Wrong - produces corrupt archive
Dim entry As ZipArchiveEntry = archive.CreateEntry(fileName)
Using writer As New BinaryWriter(entry.Open())
writer.Write(File.ReadAllBytes(docFile))
End Using
' Correct - matches the working demo
Using entry As ZipArchiveEntry = archive.CreateEntry(fileName)
Dim writer As New BinaryWriter(entry.Open())
writer.Write(File.ReadAllBytes(docFile))
writer.Flush()
End Using
Full corrected VB.NET code:
Protected Sub RadButton1_Click(sender As Object, e As EventArgs)
Dim memStream As New MemoryStream()
Using archive As ZipArchive = ZipArchive.Create(memStream)
For Each docFile As String In Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Files"))
Dim fileName As String = Path.GetFileName(docFile)
Using entry As ZipArchiveEntry = archive.CreateEntry(fileName)
Dim writer As New BinaryWriter(entry.Open())
writer.Write(File.ReadAllBytes(docFile))
writer.Flush()
End Using
Next
End Using
SendZipToClient(memStream)
End Sub
The KB article will be updated with the corrected code for both C# and VB.NET: Download Multiple Files in a Single Archive.
As a small note of gratitude for reporting the outdated KB, I have update your Telerik points. Please let us know if you have any further questions.
Regards,
Rumen
Progress Telerik
