protected void UploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { try { string contentType = HttpContext.Current.Request.Files[0].ContentType; Logger.Log(string.Format("Tryed content type is {0} ({1})", contentType, e.UploadedFile.FileName), LogLevel.Info); if (Path.GetExtension(e.UploadedFile.FileName) != ".xls") { e.IsValid = false; e.CallbackData = Utilities.GetResourceString("Validators", "NotAllowedContentTypeError"); return; } // getting DistributorId ASPxUploadControl ctrl = sender as ASPxUploadControl; if (ctrl != null && distributorIds.Keys.FirstOrDefault(k => k == ctrl.ID) == null) { e.IsValid = false; e.CallbackData = "Vyberte distributora"; return; } int distributorId = distributorIds[ctrl.ID]; string filename = FileUtils.SavePostedFile(e.UploadedFile); CanonDistributorImport <CanonImportDistributorRecord> import = new CanonDistributorImport <CanonImportDistributorRecord>(filename, distributorId, e.UploadedFile.FileName); if (!import.ExportToDb()) { e.IsValid = false; e.CallbackData = "Chyba při zpracování. Importovací soubor nemá správný formát."; } else { e.IsValid = true; e.CallbackData = "Import proběhl úspěšně."; } } catch (Exception ex) { e.IsValid = false; e.ErrorText = Utilities.GetResourceString("Validators", "GeneralFileImportError"); Logger.Log(string.Format("File {0}, exception {1}", e.UploadedFile.FileName, ex.ToString()), LogLevel.Error); } }
protected void UploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { try { string contentType = HttpContext.Current.Request.Files[0].ContentType; Logger.Log(string.Format("Tryed content type is {0} ({1})", contentType, e.UploadedFile.FileName), LogLevel.Info); if (Path.GetExtension(e.UploadedFile.FileName) != ".xls") { e.IsValid = false; e.CallbackData = Utilities.GetResourceString("Validators", "NotAllowedContentTypeError"); return; } // getting DistributorId ASPxUploadControl ctrl = sender as ASPxUploadControl; if (ctrl != null && distributorIds.Keys.FirstOrDefault(k=>k == ctrl.ID) == null) { e.IsValid = false; e.CallbackData = "Vyberte distributora"; return; } int distributorId = distributorIds[ctrl.ID]; string filename = FileUtils.SavePostedFile(e.UploadedFile); CanonDistributorImport<CanonImportDistributorRecord> import = new CanonDistributorImport<CanonImportDistributorRecord>(filename, distributorId, e.UploadedFile.FileName); if (!import.ExportToDb()) { e.IsValid = false; e.CallbackData = "Chyba při zpracování. Importovací soubor nemá správný formát."; } else { e.IsValid = true; e.CallbackData = "Import proběhl úspěšně."; } } catch (Exception ex) { e.IsValid = false; e.ErrorText = Utilities.GetResourceString("Validators", "GeneralFileImportError"); Logger.Log(string.Format("File {0}, exception {1}", e.UploadedFile.FileName, ex.ToString()), LogLevel.Error); } }