public ActionResult AddFile(HttpPostedFileBase[] Files, int ArticleId) { try { if (ModelState.IsValid) { //iterating through multiple file collection foreach (HttpPostedFileBase file in Files) { //Checking file is available to save. if (file != null) { var InputFileName = Path.GetFileName(file.FileName); var ServerSavePath = Path.Combine(Server.MapPath("/UploadedFiles/") + InputFileName); //Save file to server folder file.SaveAs(ServerSavePath); ServerSavePath = "/UploadedFiles/" + InputFileName; Flogic.AddFile(file, ArticleId, ServerSavePath); ViewBag.UploadStatus = Files.Count().ToString() + " files uploaded successfully."; } } } return(RedirectToAction("AddCategory", "Category", new { id = ArticleId })); } catch (SqlException sqlException) { return(View("Error", sqlException)); } catch (InvalidCastException invalidCastException) { return(View("Error", invalidCastException)); } }
private void CheckAdd(TextBox a, TextBox b, File file) { if (String.IsNullOrEmpty(a.Text) || String.IsNullOrEmpty(b.Text)) { MessageBox.Show("Invalid values entered. Check the input, please"); } else { fileLogic.AddFile("AddFile", file, id1); } }
public IActionResult UploadFiles(List <IFormFile> files) { if (!files.Any()) { return(RedirectToAction("Files")); } foreach (IFormFile file in files) { string newFileName = _fileLogic.AddFile(new StoredFileDTO { UserId = _accountLogic.GetCurentUserById(), FileName = file.FileName, FileSize = _shareControllerHelper.FormatSize(file.Length), UploadDate = DateTime.Now }); _fileLogic.UploadFileOnDiskAsync(_uploads, file, newFileName); } return(RedirectToAction("Files")); }