I am uploading an excel file and the data first is sent to server for server side validations in list format . If only the validation succeeds and the user submits , the file should be saved and uploaded.
But for now what's happening is , it is saving the file and then reading it from the saved file location.
sPath = WebConfigurationManager.AppSettings["UploadFilePath"]; //System.Web.Hosting.HostingEnvironment.MapPath("~/Files/");
System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
// CHECK THE FILE COUNT.
for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
{
System.Web.HttpPostedFile hpf = hfc[iCnt];
if (hpf.ContentLength > 0)
{
// CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. (AVOID DUPLICATE)
if (!System.IO.File.Exists(sPath + Path.GetFileName(hpf.FileName)))
{
///SAVE THE FILES IN THE FOLDER.
fileName = Path.GetFileName(hpf.FileName);
//hpf.SaveAs(sPath + fileName);
iUploadedCnt = iUploadedCnt + 1;
}
}
}
// RETURN A MESSAGE (OPTIONAL).
if (iUploadedCnt > 0)
{
//If you update the path here, update in web config as well
//DEPLOYMENT - comment this line
savedFilePath = "D:/Projects/Stuart V2/Stuart UI/Stuart_V2/Files/" + fileName;
ExcelPackage ep = new ExcelPackage(new FileInfo(savedFilePath));
ExcelWorksheet ws = ep.Workbook.Worksheets["Sheet1"];
..... //Convert to list and Send the list data to server
I do not want to save the file and then convert and send the data . But it reads from savedFilePath
how can I overcome that ?
Also , I have been asked to avoid using toDataTable() approach to convert excel data on the fly ?