Improved ECN file upload validation. Checking for existence of file prior to upload.

This commit is contained in:
ouellette
2023-08-10 17:33:37 -07:00
parent 9ecf6d035f
commit 7114e211f9
2 changed files with 36 additions and 21 deletions

View File

@ -520,6 +520,7 @@ namespace Fab2ApprovalSystem.Controllers
/// <returns></returns> /// <returns></returns>
public ActionResult AttachSave(IEnumerable<HttpPostedFileBase> files, int ecnNumber) public ActionResult AttachSave(IEnumerable<HttpPostedFileBase> files, int ecnNumber)
{ {
string returnString = "";
// The Name of the Upload component is "files" // The Name of the Upload component is "files"
if (files != null) if (files != null)
{ {
@ -533,30 +534,44 @@ namespace Fab2ApprovalSystem.Controllers
DirectoryInfo di = new DirectoryInfo(ecnFolderPath); DirectoryInfo di = new DirectoryInfo(ecnFolderPath);
if (!di.Exists) if (!di.Exists)
di.Create(); try
{
di.Create();
}
catch
{
returnString = "Error creating ECN directory.";
}
if (returnString == "")
{
var physicalPath = Path.Combine(ecnFolderPath, fileName);
if (!System.IO.File.Exists(physicalPath))
{
file.SaveAs(physicalPath);
ECNAttachment attach = new ECNAttachment()
{
ECNNumber = ecnNumber,
FileName = fileName,
UserID = (int)Session[GlobalVars.SESSION_USERID],
};
if (System.IO.File.Exists(physicalPath))
{
var physicalPath = Path.Combine(ecnFolderPath, fileName); ecnDMO.InsertECNAttachment(attach);
}
file.SaveAs(physicalPath); else
ECNAttachment attach = new ECNAttachment() {
{ returnString = "File was not uploaded to server.";
ECNNumber = ecnNumber, }
FileName = fileName, }
UserID = (int)Session[GlobalVars.SESSION_USERID], else
}; {
if (System.IO.File.Exists(physicalPath)) returnString = "Cannot have duplicate file names.";
{ }
ecnDMO.InsertECNAttachment(attach);
} }
else
{
throw new Exception();
}
} }
} }
return Content(""); return Content(returnString);
} }
/// <summary> /// <summary>

View File

@ -2092,7 +2092,7 @@
grid.dataSource.read($('#txtECNNumber').val()); grid.dataSource.read($('#txtECNNumber').val());
} }
function onFileUploadError(e) { function onFileUploadError(e) {
alert("Error Uploading File!!! Please Try Again..."); alert("Error Uploading File!!! " + e.XMLHttpRequest.responseText);
var grid = $("#Attachments").data("kendoGrid"); var grid = $("#Attachments").data("kendoGrid");
grid.dataSource.read($('#txtECNNumber').val()); grid.dataSource.read($('#txtECNNumber').val());
} }