gerardo-lijs / CrystalReportsRunner

Runner to allow the use of Crystal Reports in .NET Core using external process (in .NET Framework 4.8) and named pipes for communication
MIT License
61 stars 19 forks source link

in ASP.net 6 MVC app it run on localpc and open the crystal report but when it hosted in local IIS it wont work. #8

Closed skasad21 closed 1 year ago

mhmd-azeez commented 1 year ago

Hello @skasad21 can you provide any details why it won't work? An error message would be great

skasad21 commented 1 year ago

Actually I am kind of noob so. Let me explain what i did. I download the sample project you give then i add a .net core MVC project. Then Add a button on view page and in controller i add a method. In side the method i actually did nothing new just copy all the code from sample console app. only edit i did was copy dataset and report file in a seperate folder and add then in the method. So, it dont give me any error work great but when i hosted it in my local IIS then it wont work. i mean no crystal report open.

Controller code : public async void ShowReportAsync() { string webRootPath = _env.WebRootPath; await reportClass.testreportAsync(webRootPath); }

Method:

    public static async Task testreportAsync(string webRootPath)
    {
        try
        {
            // ========== Initializing Engine ===========

            // Method 1: With Connection string
            using var engine = new CrystalReportsEngine();

            // Method 2: Without Connection string
            // using var engine = new CrystalReportsEngine();

            // ========== Customizing Viewer Settings ===========

            engine.ViewerSettings.AllowedExportFormats =
                ReportViewerExportFormats.PdfFormat |
                ReportViewerExportFormats.ExcelFormat |
                ReportViewerExportFormats.CsvFormat |
                ReportViewerExportFormats.WordFormat |
                ReportViewerExportFormats.XmlFormat |
                ReportViewerExportFormats.RtfFormat |
                ReportViewerExportFormats.ExcelRecordFormat |
                ReportViewerExportFormats.EditableRtfFormat |
                ReportViewerExportFormats.XLSXFormat |
                ReportViewerExportFormats.XmlFormat;

            engine.ViewerSettings.ShowRefreshButton = false;
            engine.ViewerSettings.ShowCopyButton = false;
            engine.ViewerSettings.ShowGroupTreeButton = false;
            engine.ViewerSettings.ShowParameterPanelButton = false;
            engine.ViewerSettings.EnableDrillDown = false;
            engine.ViewerSettings.ToolPanelView = ReportViewerToolPanelViewType.None;
            engine.ViewerSettings.ShowCloseButton = false;
            engine.ViewerSettings.EnableRefresh = false;               

            engine.ViewerSettings.SetUICulture(Thread.CurrentThread.CurrentUICulture);

            // ========== Showing the Report ===========
            var dataset = new PersonDataset();

            var personsTable = dataset.Tables["Persons"];

            for (int i = 0; i < 100; i++)
            {
                var row = personsTable!.NewRow();
                row["Name"] = $"Person {i + 1}";
                personsTable.Rows.Add(row);
            }

            // Method 1: Full Control
            // string test = _hostingEnvironment.WebRootPath;
            string test = webRootPath + @"\sReport\DatasetReport.rpt";
            var report = new Report(test, "Sample Report")
            {
                DataSets = new List<System.Data.DataSet> { dataset }
            };
            report.Parameters.Add("ComputerName", Environment.MachineName);

            await engine.ShowReport(report);
            Console.ReadKey();

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }           

    }

    Thanks for the reply. 
mhmd-azeez commented 1 year ago

@skasad21 can you please upload the Runner logs here? By default it's in ProgramData/LijsDev/CrystalReportRunner/logs. But you can also specify it through setting engine.LogDirectory

skasad21 commented 1 year ago

What I did is: Add This line engine.LogDirectory = @"C:\ProgramData\LijsDev\CrystalReportRunner\logs"; After await engine.ShowReport(report); That line When i run locally it dont create any log file

Also after publishing again in Local IIS it dont create any log file

Let me know if i make any mistake. And also how can i share full code with you?

mhmd-azeez commented 1 year ago

Yeah, that'd be helpful. But I am not sure if the Runner works for ASP.NET MVC, as we have only tested it with desktop apps (WPF/WinForms)

skasad21 commented 1 year ago

How can i share the code with you ? In project it work well but if hosted in Local IIS it won't work. Let me know how can i share the code with yo.

mhmd-azeez commented 1 year ago

if it's okay, please zip it (remove the bin/obj folder first plesae) and upload it here

skasad21 commented 1 year ago

CrystalReportsRunnertest.zip

skasad21 commented 1 year ago

Sorry for late reply in my previous comments you will get the files. I deleted bin/obj folder

Rog4ner commented 1 year ago

In web apps, I think it's a better idea to export the report in PDF format and show it in a route of your web app, instead of using the method engine.ShowReport you can use the engine.Export method. Or this is not an option?

gerardo-lijs commented 1 year ago

Agree with @Rog4ner . In web applications you usually export to PDF. The runners show methods/UI are meant for desktop apps and use the Crystal Reports Viewer for WPF, they won't work in the web.

skasad21 commented 1 year ago

I thought it will work on .net 6 MVC project.

mhmd-azeez commented 1 year ago

@skasad21 does engine.Export work? Because even if ShowReport works, it provides no value for web apps since your users can't see what's on your server

skasad21 commented 1 year ago

Sorry for really late reply. One interesting things i saw when i click on the show button i saw "LijsDev Crystal Reports Runner" process start but can't find the report file when i am hosting my site on Local IIS. but when i running from my project solution it work perfectly.

gerardo-lijs commented 1 year ago

Closing this stale issue. Please re-open if still trying to make it work for web projects