Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on web api 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
return false

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:

        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))
            bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
            if (areIdentical == true)
// return true
// retur false

Updated 16-Jun-21 22:16pm
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.
Share this answer
Maciej Los 17-Jun-21 4:46am    

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