Click here to Skip to main content
15,397,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on web api asp.net core 2.2
I face issue I can't return true or false from web api compare excel as below
so if excel is identical
then return true
else
return false

C#
public bool CompareExcel(string filePath, string templatePath, out int rowCount, out string error)
        {
            error = ""; rowCount = 0;
            bool areIdentical = false;
            string templateSheetName = "";
            List<string> columns;
            GetTemplateSchema(templatePath, out templateSheetName, out columns);
            areIdentical = CompareBySchema(filePath, templateSheetName, columns, out rowCount, out error);
            return areIdentical;
        }


What I have tried:

ASP.NET
[HttpGet]
        [Route("CompareExcel")]
        public IActionResult CompareExcel()
        {
          
            var DisplayFileName = Request.Form.Files[0];
            string fileName = DisplayFileName.FileName.Replace(".xlsx", "-") + Guid.NewGuid().ToString() + ".xlsx";
            string Month = DateTime.Now.Month.ToString();
            string DirectoryCreate = Path.Combine(myValue1, Month);// myValue1 + "\\" + Month + "\\" + fileName;
            CExcel ex = new CExcel();
        
            string error = "";
            int rowCount = 0;
      
            var filedata = ContentDispositionHeaderValue.Parse(Request.Form.Files[0].ContentDisposition).FileName.Trim('"');
            var dbPath = Path.Combine(DirectoryCreate, fileName);
            var InputfilePath = System.IO.Path.Combine(GetFilesDownload, "Gen.xlsx");
            using (var stream = new FileStream(dbPath, FileMode.Create))
            {
                Request.Form.Files[0].CopyTo(stream);
                stream.Flush();
                stream.Close();
            }
            GC.Collect();
            bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
            if (areIdentical == true)
            {
// return true
            }
            else
            {
// retur false

            }
        }
Posted
Updated 16-Jun-21 22:16pm
Comments
Maciej Los 17-Jun-21 2:14am
   
Have you tried to debug your code?
ahmed_sa 17-Jun-21 2:22am
   
yes but i don't know how to get true or false from api

1 solution

Most of the work is already done in the controller, you just need to return the correct IActionResult from the controller method. This tutorial page[^] has some good examples of what you can return, you just need to see which one applies here.
   
Comments
Maciej Los 17-Jun-21 4:46am
   
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900