locked
Display List<string> returned from a method RRS feed

  • Question

  • 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

    Wednesday, August 26, 2015 11:53 AM

Answers

  • User325035487 posted

    Figured it out

    List<string> messages = new List<string>();
    messages = test.ImportManu(fi);
    foreach (var r in messages)
            {
                <p>@r.ToString()</p>
            }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 27, 2015 1:31 AM