private void convertButton_Click(object sender, EventArgs e) { int count = 0; foreach (var file in bordFiles) { try { var convertedFile = new BordereauCoordinator(file).CreateReport(); outputTextbox.Text += "Created file: " + convertedFile + Environment.NewLine; count++; } catch (Exception) { outputTextbox.Text += String.Format("Something went wrong with file {0}{1}",file.FullName, Environment.NewLine); } } outputTextbox.Text += String.Format("------------- {0} files converted -------------", count) + Environment.NewLine + Environment.NewLine; }
public ActionResult SaveUploadedFile() { bool isSavedSuccessfully = true; string key = Guid.NewGuid().ToString(); try { foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; //Save file content goes here if (file != null && file.ContentLength > 0) { var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\WallImages", Server.MapPath(@"\"))); string pathString = System.IO.Path.Combine(originalDirectory.ToString(), key); var fileName1 = Path.GetFileName(file.FileName); bool isExists = System.IO.Directory.Exists(pathString); if (!isExists) System.IO.Directory.CreateDirectory(pathString); var path = string.Format("{0}\\{1}", pathString, file.FileName); file.SaveAs(path); var convertedFile = new BordereauCoordinator(new FileInfo(path)).CreateReport(); return File(convertedFile, "text/CSV"); } } } catch (Exception ex) { isSavedSuccessfully = false; } if (isSavedSuccessfully) { return Json(new { Message = key }); } else { return Json(new { Message = "Error in saving file" }); } }