User325035487 posted
I followed this article
https://www.paragon-inc.com/resources/blogs-posts/easy_excel_interaction_pt6 to Import data in to MS Sql Server from Excel using EP Plus. The import is working perfectly.
public List<string> ImportManu(FileInfo file)
{
var resultMessages = new List<string>();
var totalImported = 0;
try
{
using (var excelPackage = new ExcelPackage(file))
{
//My Import code here which works fine,
}
resultMessages.Insert(0,string.Format("{0} records successfully imported.\n",totalImported));
return resultMessages;
}
catch (IOException ex)
{
resultMessages.Add("File still open. Please close Excel File before importing!");
return resultMessages;
}
Please tell me how I can get the resultMessages and totalImported and display it in Razor Web Page.
I have the above code in a cs file in my App_Code folder
This is my code for uploading and calling this method
if (IsPost)
{
var xlsRoot = Server.MapPath("~/App_Data/Uploaded/");
var filename = Guid.NewGuid().ToString() + ".xlsx";
var umSavePath = Path.Combine(xlsRoot, filename);
var excelfile = Request.Files["excelmanu"];
excelfile.SaveAs(umSavePath);
ImportXLSX test = new ImportXLSX();
FileInfo fi = new FileInfo(umSavePath);
test.ImportManu(fi);
}
Thanks in advance