Hi I also created an zip file extractor in c# which would read, display and extract the selected zip file. Below is the code for reading and displaying the contents of the zip file in a listbox. Now I want to display an error message box if the zip file is corrupt or not readable or extractable. Because if there is no error message displayed, the application just crashes and displays this message: System.IO.InvalidDataException: 'End of Central Directory record could not be found.' while reading zip file
Code for reading and displaying non-corrupt zip files:
openFileDialog1.Filter = "ZIP Folders (.ZIP)|*.zip";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
ZipArchive zip = ZipFile.OpenRead(openFileDialog1.FileName);
listBox1.Items.Clear();
foreach (ZipArchiveEntry entry in zip.Entries)
{
listBox1.Items.Add(entry.FullName);
}
}