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>
|
/// <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>
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user