public ActionResult UploadFiles(HttpPostedFileBase[] files, string Upload, string Submit) { //Ensure model state is valid if (ModelState.IsValid) { if (!string.IsNullOrEmpty(Upload)) { StartTime = DateTime.Now; string fileName = string.Empty; string destinationPath = string.Empty; List <MultipleFileModel> uploadFileModel = new List <MultipleFileModel>(); Dictionary <string, string> listOfFiles = new Dictionary <string, string>(); //iterating through multiple file collection foreach (HttpPostedFileBase file in files) { //Checking file is available to save. if (file != null) { destinationPath = Path.Combine(Server.MapPath("~/TempFiles/"), file.FileName); var InputFileName = Path.GetFileName(file.FileName); var ServerSavePath = Path.Combine(Server.MapPath("~/TempFiles/") + InputFileName); //Save file to server folder file.SaveAs(ServerSavePath); //assigning file uploaded status to ViewBag for showing message to user. listOfFiles.Add(file.FileName, destinationPath); AntivirusTesting.Utility.Testing testing = new AntivirusTesting.Utility.Testing(); var infected = testing.Execute(listOfFiles); uploadFileModel.Add(new MultipleFileModel { FileName = file.FileName, FilePath = destinationPath, ScanReport = infected }); } } Session["fileUploader"] = uploadFileModel; ViewBag.Message = "File Uploaded Successfully"; EndTIme = DateTime.Now; ViewBag.UploadStatus = files.Count().ToString() + " files " + files.Select(f => f.ContentLength).Sum().ToString() + " kb " + EndTIme.Subtract(StartTime).ToString() + " Secs"; WriteLog("Vikash", StartTime, EndTIme); } if (!string.IsNullOrEmpty(Submit)) { string rootFolderPath = Server.MapPath("~/TempFiles/"); string destinationPath = Server.MapPath("~/MyFiles/"); string[] fileList = System.IO.Directory.GetFiles(rootFolderPath); foreach (string file in fileList) { string fileToMove = Path.Combine(rootFolderPath, file); string moveTo = Path.Combine(destinationPath, file); //moving file System.IO.File.Move(fileToMove, moveTo); Dictionary <string, string> listOfFiles = new Dictionary <string, string>(); listOfFiles.Add(file, moveTo); AntivirusTesting.Utility.Testing testing = new AntivirusTesting.Utility.Testing(); testing.Execute(listOfFiles); } } } return(View()); }
public ActionResult FileUpload(HttpPostedFileBase file_Uploader) { if (file_Uploader != null) { StartTime = DateTime.Now; string fileName = string.Empty; string destinationPath = string.Empty; List <FileUploadModel> uploadFileModel = new List <FileUploadModel>(); fileName = Path.GetFileName(file_Uploader.FileName); destinationPath = Path.Combine(Server.MapPath("~/TempFiles/"), fileName); file_Uploader.SaveAs(destinationPath); if (Session["fileUploader"] != null) { var isFileNameRepete = ((List <FileUploadModel>)Session["fileUploader"]).Find(x => x.FileName == fileName); if (isFileNameRepete == null) { uploadFileModel.Add(new FileUploadModel { FileName = fileName, FilePath = destinationPath }); ((List <FileUploadModel>)Session["fileUploader"]).Add(new FileUploadModel { FileName = fileName, FilePath = destinationPath }); ViewBag.Message = "File Uploaded Successfully"; Dictionary <string, string> listOfFiles = new Dictionary <string, string>(); listOfFiles.Add(fileName, destinationPath); AntivirusTesting.Utility.Testing testing = new AntivirusTesting.Utility.Testing(); testing.Execute(listOfFiles); } else { ViewBag.Message = "File is already exists"; } } else { uploadFileModel.Add(new FileUploadModel { FileName = fileName, FilePath = destinationPath }); Session["fileUploader"] = uploadFileModel; Dictionary <string, string> listOfFiles = new Dictionary <string, string>(); listOfFiles.Add(fileName, destinationPath); AntivirusTesting.Utility.Testing testing = new AntivirusTesting.Utility.Testing(); testing.Execute(listOfFiles); ViewBag.Message = "File Uploaded Successfully"; } EndTIme = DateTime.Now; WriteLog("Vikash", StartTime, EndTIme); } return(View()); }