public JsonResult UpdateFiles(string TxID) { string sMessage = ""; bool status = false; try { if (Request.Files.Count > 0) { int MaxNumber = 0; HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { string Filename = Path.GetFileName(Request.Files[i].FileName); HttpPostedFileBase File = files[i]; string sDestinationPath = File.FileName; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = File.FileName.Split(new char[] { '\\' }); sDestinationPath = testfiles[testfiles.Length - 1]; } var oldRecord = db.tbl_sasAttachments.FirstOrDefault(p => p.transaction_ID == TxID); if (oldRecord != null) { MaxNumber = db.tbl_sasAttachments.Where(p => p.transaction_ID == TxID).Max(p => p.attachment_Index); sDestinationPath = Path.Combine(Server.MapPath("~/Images/"), sDestinationPath); File.SaveAs(sDestinationPath); tbl_sasAttachments oAttachment = new tbl_sasAttachments(TxID, ++MaxNumber, (int)enumFormNames.Task, Filename, Filename); db.tbl_sasAttachments.Add(oAttachment); } else { sDestinationPath = Path.Combine(Server.MapPath("~/Images/"), sDestinationPath); File.SaveAs(sDestinationPath); tbl_sasAttachments oAttachment = new tbl_sasAttachments(TxID, ++MaxNumber, (int)enumFormNames.Task, Filename, Filename); db.tbl_sasAttachments.Add(oAttachment); } } var Task = db.tbl_pmsTxTask.FirstOrDefault(p => p.task_ID == TxID); if (Task != null) { Task.isAttachment = true; db.SaveChanges(); } db.SaveChanges(); status = true; sMessage = "File Uploaded Successfully!"; } } catch (Exception ex) { status = false; sMessage = "Error occurred. Error details: " + ex.Message; } return(new JsonResult { Data = new { status = status, Message = sMessage } }); }
public JsonResult UploadFiles(string TxID) { string sMessage = ""; bool status = false; try { if (Request.Files.Count > 0) { string path1 = Server.MapPath("~/Images/"); if (!System.IO.Directory.Exists(path1)) { status = false; sMessage = "File Upload Folder Not Found"; } else { HttpFileCollectionBase FileList = Request.Files; for (int i = 0; i < FileList.Count; i++) { //string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/"; string Filename = Path.GetFileName(Request.Files[i].FileName); HttpPostedFileBase File = FileList[i]; string sDestinationPath = File.FileName; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = File.FileName.Split(new char[] { '\\' }); sDestinationPath = testfiles[testfiles.Length - 1]; } // Get the complete folder path and store the file inside it. sDestinationPath = Path.Combine(Server.MapPath("~/Images/"), sDestinationPath); File.SaveAs(sDestinationPath); tbl_sasAttachments oAttachment = new tbl_sasAttachments(TxID, ++i, (int)enumFormNames.Task, Filename, Filename); db.tbl_sasAttachments.Add(oAttachment); } var Task = db.tbl_pmsTxTask.FirstOrDefault(p => p.task_ID == TxID); if (Task != null) { Task.isAttachment = true; db.SaveChanges(); } db.SaveChanges(); status = true; sMessage = "File Uploaded Successfully!"; } } } catch (Exception ex) { status = false; sMessage = "Error occurred. Error details: " + ex.Message; } return(new JsonResult { Data = new { status = status, Message = sMessage } }); }