This is a migrated thread and some comments may be shown as answers.

PDF Render directly

5 Answers 983 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Louis asked on 03 Jul 2019, 03:46 AM

Hello.

 

3 questions :

1) I use ASP.NET MVC Core report (last version).  Everything works fine with the viewer.  Thanks a lot to TELERIK.

I want generate directy a PDF version of the report.  Like user click on a link and the report is downloaded directly.

Can I have some sample to doing this (C#)?

 

2) And how I can use    @(Html.TelerikReporting().ReportViewer() rather javascript :

        $(document).ready(function () {

            $("#reportViewer1")
                .telerik_ReportViewer({

 

 ...TelerikReporting() is always in red.  Nuget missing?  See attachement for the ones in have in my project.

 

3) ReportingEngineConfiguration is misssing in ReportController.  See attachement.

 

 

 

5 Answers, 1 is accepted

Sort by
0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Jul 2019, 12:24 PM
Sorry see attachment for question #3.
0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 04 Jul 2019, 01:02 PM

Ok i got the answer for the question #1.  If it's can help someone else too.

 

public  FileStreamResult Imprimer(string id)
{
    if (!String.IsNullOrEmpty(id))
    {
        if (Guid.TryParse(id, out Guid Id))
        {
            Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
 
            // set any deviceInfo settings if necessary
            System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
             
            var uriReportSource = new Telerik.Reporting.UriReportSource();
 
            // Specifying an URL or a file path
            uriReportSource.Uri = @"C:\Users\Lo\Source\Repos\HazMat\HazMat\wwwroot\Reports\Report1.trdp";
            uriReportSource.Parameters.Add("NoMat", id);
          
            Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", uriReportSource, deviceInfo);                  
             
            // Écrire le fichier en mémoire plutôt que sur le disque.
            MemoryStream ms = new MemoryStream();
            ms.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            ms.Seek(0, SeekOrigin.Begin);//set position to beginning.  Semble nécessaire lors du return.
            ms.Flush();
            // Il faut ajouter l'extension car "application/pdf" n'indique rien
            return new FileStreamResult(ms, "application/pdf") { FileDownloadName = result.DocumentName + ".pdf" };
        }
    }
    return null;
}

 

 

0
Neli
Telerik team
answered on 05 Jul 2019, 02:04 PM
Hi Louis,

Let me start with the second question:
The only viewer that may be used in a .NET Core application is the pure HTML5 Viewer. The MVC Viewer cannot be used in .NET Core. This means that the reportSource is a pure JavaScript object.

About the third question:
I suggest to take a look at our How to implement Telerik Reporting in ASP.NET Core 2.1 MVC KB article to compare your code with the sample. Note that it might depend where the ConfigurationService is implemented. For example, in our demo it is located in the Startup class. Then the method in the ReportsContrоller is 
public ReportsController(Startup.ConfigurationService configSvc) .


Regards,
Neli
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 05 Jul 2019, 05:50 PM

Hello Neli,

 

THank  you for the fast answer.  But I still this issue (question #3) : ReportingEngineConfiguration is misssing in ReportController.

When I compare the definition of my project to the demo project telerik provide (AspNetCoreMvcDemo) I notice this :

My project :

#region Assembly Telerik.Reporting, Version=13.1.19.618, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
// C:\Users\Louis\.nuget\packages\telerik.reporting\13.1.19.618\lib\net40\Telerik.Reporting.dll
#endregion

your project :

#region Assembly Telerik.Reporting, Version=13.0.19.222, Culture=neutral, PublicKeyToken=a9d7983dfcc261be
// C:\Users\Louis\.nuget\packages\telerik.reporting\13.0.19.222\lib\netstandard2.0\Telerik.Reporting.dll
#endregion

 

So my main question :  what is the way to provide the connection string using report nuget package (that use net40)  (see atachement)?  It's seem not the same way as you show in your demo project.

I try to use netstandard2.0 in my project but got this error :

An error occurred while starting the application.
TypeLoadException: Violation des règles de sécurité liées à l'héritage par le type 'Telerik.Reporting.Services.AspNetCore.ReportsControllerBase'. Les types dérivés doivent correspondre à l'accessibilité à la sécurité du type de base ou être moins accessibles.
Unknown location
 
ReflectionTypeLoadException: Impossible de charger un ou plusieurs des types requis. Extrayez la propriété LoaderExceptions pour plus d'informations.
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
 
Loader Exceptions:
Violation des règles de sécurité liées à l'héritage par le type 'Telerik.Reporting.Services.AspNetCore.ReportsControllerBase'. Les types dérivés doivent correspondre à l'accessibilité à la sécurité du type de base ou être moins accessibles.
TypeLoadException: Violation des règles de sécurité liées à l'héritage par le type 'Telerik.Reporting.Services.AspNetCore.ReportsControllerBase'. Les types dérivés doivent correspondre à l'accessibilité à la sécurité du type de base ou être moins accessibles.

 

 

 

 

 

 

0
Louis
Top achievements
Rank 1
Iron
Iron
Iron
answered on 05 Jul 2019, 09:32 PM

Hello Neli,

I got the solution after few hours on this case.  Thank you and have nice week-ned you and your team.

Tags
General Discussions
Asked by
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Louis
Top achievements
Rank 1
Iron
Iron
Iron
Neli
Telerik team
Share this question
or