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,30 +534,44 @@ namespace Fab2ApprovalSystem.Controllers
DirectoryInfo di = new DirectoryInfo(ecnFolderPath);
if (!di.Exists)
di.Create();
var physicalPath = Path.Combine(ecnFolderPath, fileName);
file.SaveAs(physicalPath);
ECNAttachment attach = new ECNAttachment()
{
ECNNumber = ecnNumber,
FileName = fileName,
UserID = (int)Session[GlobalVars.SESSION_USERID],
};
if (System.IO.File.Exists(physicalPath))
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))
{
ecnDMO.InsertECNAttachment(attach);
ecnDMO.InsertECNAttachment(attach);
}
else
{
returnString = "File was not uploaded to server.";
}
}
else
{
returnString = "Cannot have duplicate file names.";
}
}
else
{
throw new Exception();
}
}
}
return Content("");
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());
}