Using ZipArchive
how can I check if a file is a valid zip archive?
I am currently catching an InvalidDataException
when attempting to enumerate through the zip entries but I don't believe that this is the best way to do this:
public static bool IsCompressed(this HttpPostedFile postedFile)
{
try
{
var entries = new ZipArchive(postedFile.InputStream).Entries;
return true;
}
catch (InvalidDataException)
{
return false;
}
}