private void UploadZipFile(ZipFile zip) { byte[] _bytes; List<filenameAndBytesStruct> plfFiles = new List<filenameAndBytesStruct>(); filenameAndBytesStruct oneFile; foreach (ZipEntry fileEntry in zip) { if (fileEntry.IsFile) { Stream zipStr = zip.GetInputStream(fileEntry); _bytes = new byte[fileEntry.Size]; zipStr.Read(_bytes, 0, (int)fileEntry.Size); if (BLL.DataBlock.checkDataBlock(_bytes)) { UploadFileToBase(fileEntry.Name, _bytes); } if (fileEntry.Name.Substring(fileEntry.Name.Length - 4, 4).ToLower() == ".plf") { oneFile = new filenameAndBytesStruct(); oneFile.filename = fileEntry.Name; oneFile._bytes = _bytes; plfFiles.Add(oneFile); } } } if (plfFiles.Count != 0) SelectDriverForPLF(); Session["FileUpload"] = plfFiles; }
protected void Upload_Click(object Sender, EventArgs e) { string fileName = MyFileUpload.PostedFile.FileName; //hide message block ErrorMessageBlock.Visible = false; //hide combobox for drivers SelectPLFDriver.Visible = false; FileList.Visible = false; UploadPanel.Visible = true; try { int bytesLenght = Convert.ToInt32(MyFileUpload.PostedFile.InputStream.Length); //if file is empty if (bytesLenght == 0) { ErrorMessage.Text = "Ошибка: Выберите файл для загрузки."; //show error block ErrorMessageBlock.Visible = true; } else { //hide error block ErrorMessageBlock.Visible = false; byte[] _bytes = new byte[bytesLenght]; int bytesSize = 0; if (MyFileUpload.PostedFile.ContentType != null) { bytesSize = MyFileUpload.PostedFile.InputStream.Read(_bytes, 0, bytesLenght); if (fileName.Substring(fileName.Length - 4, 4).ToLower() == ".zip") { ZipFile zip = new ZipFile(MyFileUpload.PostedFile.InputStream); UploadZipFile(zip); return; } else { if (fileName.Substring(fileName.Length - 4, 4).ToLower() == ".plf") { if (SelectPLFDriver.Visible == false) { List<filenameAndBytesStruct> listOfPLFS = new List<filenameAndBytesStruct>(); filenameAndBytesStruct onePlf = new filenameAndBytesStruct(); onePlf.filename = fileName; onePlf._bytes = _bytes; listOfPLFS.Add(onePlf); Session["FileUpload"] = listOfPLFS; SelectDriverForPLF(); return; } } else { if (BLL.DataBlock.checkDataBlock(_bytes)) { UploadFileToBase(fileName, _bytes); } else { throw new Exception("Неверный формат файла"); } } } } } } catch (Exception ex) { ErrorMessage.Text = "Ошибка: " + ex.Message; //show error block ErrorMessageBlock.Visible = true; } }