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>
public ActionResult AttachSave(IEnumerable<HttpPostedFileBase> files, int ecnNumber)
{
string returnString = "";
// The Name of the Upload component is "files"
if (files != null)
{
@ -533,10 +534,19 @@ namespace Fab2ApprovalSystem.Controllers
DirectoryInfo di = new DirectoryInfo(ecnFolderPath);
if (!di.Exists)
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()
{
@ -551,12 +561,17 @@ namespace Fab2ApprovalSystem.Controllers
}
else
{
throw new Exception();
}
returnString = "File was not uploaded to server.";
}
}
return Content("");
else
{
returnString = "Cannot have duplicate file names.";
}
}
}
}
return Content(returnString);
}
/// <summary>

View File

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