Improved ECN file upload validation. Checking for existence of file prior to upload.
This commit is contained in:
@ -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>
|
||||
|
@ -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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user