public static string CheckValidZipFile(HttpPostedFileBase file) { if (!FileTypeDetector.IsZipFile(file)) { return("Input file is not .zip file"); } file.InputStream.Position = 0; if (!CheckImageZipFile(file)) { return("Zip file is empty or contains invalid image file"); } file.InputStream.Position = 0; return(null); }
private static bool CheckImageZipFile(HttpPostedFileBase file) { //true: leaveOpen after read, so that file stream will not be disposed using (ZipArchive archive = new ZipArchive(file.InputStream, ZipArchiveMode.Read, true)) { if (archive.Entries.Count == 0) { return(false); } foreach (var entry in archive.Entries) { if (!FileTypeDetector.IsImageFile(entry.Open())) { return(false); } } } return(true); }
public static string CheckValidExcelFile(HttpPostedFileBase file) { if (!FileTypeDetector.IsExcelFile(file)) { return("Input file is not vaild excel file"); } file.InputStream.Position = 0; if (!CheckExcelFileHeader(file)) { return("Excel file is missing some column"); } file.InputStream.Position = 0; if (GetNumberOfRecord(file) == 0) { return("Excel does not contains any record"); } file.InputStream.Position = 0; return(null); }