public JsonResult UploadAndUpdateForm(string categoryId, string categoryName, string formName, string formVersion, string modifiedSection) { List <Forms> formList = new List <Forms>(); DocumentBL uploadBL = new DocumentBL(); if (Request.Files.Count == 1) { try { string tempFolder = "~/UploadForUpdate/"; string relativePath = "~/Forms/" + categoryName; // deep string path = Server.MapPath("~/Forms/"); // deep //string tempath = Server.MapPath(tempFolder); string fileFath = Path.Combine(path, categoryName); //if (!Directory.Exists(tempath)) //{ // Directory.CreateDirectory(fileFath); //} // Get all files from Request object #region form to Archive string archivedFolder = "~/ArchivedForms/" + categoryName + "/"; string uploadedFolder = "~/Forms/" + categoryName + "/"; // deep string sourcePath = Server.MapPath(uploadedFolder); string destinationPath = Server.MapPath(archivedFolder); string uploadedFile = Path.Combine(sourcePath, formName); string archiveFile = Path.Combine(destinationPath, formName); if (System.IO.File.Exists(uploadedFile)) { if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } //System.IO.File.Move(uploadedFile, archiveFile); System.IO.File.Copy(uploadedFile, archiveFile, true); } #endregion HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { Forms form = new Forms(); HttpPostedFileBase file = files[i]; string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } // Get the complete folder path and store the file inside it. string fnameWithPath = Path.Combine(fileFath, fname); file.SaveAs(fnameWithPath); //form.FormName = fname; form.FormName = formName; form.FilePath = fileFath; form.CategoryId = Convert.ToInt32(categoryId); form.Version = formVersion; form.CreateedBy = 1; form.ModifiedSection = modifiedSection; // deep formList.Add(form); } int count = uploadBL.SaveUploadedForms(formList); // Returns message that successfully uploaded return(Json("File Updated Successfully!")); } catch (Exception ex) { return(Json("Error occurred. Error details: " + ex.Message)); } } else { return(Json("No files selected.")); } }
public ActionResult UploadFiles(FormsCategory category, string categoryId, string categoryName, List <HttpPostedFileBase> fileData) { List <Forms> formList = new List <Forms>(); DocumentBL uploadBL = new DocumentBL(); if (Request.Files.Count > 0) { try { string relativePath = "~/Uploads/" + categoryName; string path = Server.MapPath("~/Uploads/"); string fileFath = Path.Combine(path, categoryName); if (!Directory.Exists(fileFath)) { Directory.CreateDirectory(fileFath); } // Get all files from Request object HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { Forms form = new Forms(); //string path = AppDomain.CurrentDomain.BaseDirectory + "Uploads/"; //string filename = Path.GetFileName(Request.Files[i].FileName); HttpPostedFileBase file = files[i]; string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } // Get the complete folder path and store the file inside it. string fnameWithPath = Path.Combine(fileFath, fname); file.SaveAs(fnameWithPath); form.FormName = fname; form.FilePath = fileFath; form.CategoryId = Convert.ToInt32(categoryId); form.CreateedBy = 1; formList.Add(form); } int count = uploadBL.SaveUploadedForms(formList); // Returns message that successfully uploaded return(Json("File Uploaded Successfully!")); } catch (Exception ex) { return(Json("Error occurred. Error details: " + ex.Message)); } } else { return(Json("No files selected.")); } }