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

How to generate a standalone report from an ASP.NET MVC web application?

4 Answers 423 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 28 Jul 2014, 06:40 PM

Hello, I am new to Telerik. I want to have a button in my ASP.NET MVC web application that when clicked:

  1. executes a .trdx standalone Telerik file
  2. exports the output to a Word file

I don't know how to get started with this, what tutorial might help explain this? What sort of methods might be available? Here is my pseudo-code of what I would like to do:

string filePath = Server.MapPath("~/reportFolder/reportFile.trdx");
// I made this stuff up:
Telerik.StandaloneReport myReport = new Telerik.StandaloneReport(filePath);
myReport.executeAndPromptTheUserToSaveAs();

I have the .trdx file linked to my database, and so it is already correctly processing the report I want. Keep in mind that I don't want to embed the report in the web application in any way, I just want to "Save as..." the output of the .trdx report file when clicking a button in the application.

4 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 30 Jul 2014, 04:30 PM
Hi Ian,

If you do not intend to display the report in a report viewer, you can use custom UI to post to your controller's action in which the report is exported programmatically and the file result is sent back to the client.

You will need to copy the connection strings used in the report in the start application's configuration file. Also if you use the Open XML formats (DOCX, XLSX) you will need to add references to Telerik.Reporting.OpenXmlRendering.dll and Open XML SDK 2.0 for Microsoft Office (DocumentFormat.OpenXml.dll v.2.0.5022.0 or above).


I hope the above information helps you.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ian
Top achievements
Rank 1
answered on 05 Aug 2014, 10:13 PM
Thanks very much Stef for the help!

So I now have the .dll assemblies you mentioned, and have successfully compiled the sample code you mentioned found at http://www.telerik.com/help/reporting/programmatic-exporting-report.html#cbc_1 . I'm using the "DOCX" format instead of "PDF" that the example uses.

However, I don't know how to correctly use this line from the example code:
// reportName is the Assembly Qualified Name of the report
typeReportSource.TypeName = reportName;

This is my attempt, which yields the error ArgumentException "Invalid report type":
typeReportSource.TypeName = Server.MapPath("~/Telerik/DashboardReport.trdx");

The above-mentioned exception occurs on this line from the example code:
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("DOCX", typeReportSource, deviceInfo);


So how do I correctly set this TypeName property, and how do I link to my .trdx file?
0
Accepted
Stef
Telerik team
answered on 08 Aug 2014, 12:36 PM
Hello,

The AssemblyQualifiedName of an object is a string structured as follows:
<full_namespace>.<type_name>, <assembly_name>
It can be used with the reporting TypeReportSource to specify a report created with the integrated in Visual Studio Report Designer. If the report is in an external DLL, the DLL must be referenced in the viewer's project, where both projects must use the same Telerik Reporting version.Using reflection we create internally an instance of the report type through its default constructor.

If the reports are saved in TRDX files, you can use a UriReportSource and set its Uri property to the file path.

For more details about report source types and their usage, please check the Report Sources help article.


Let us know if you have any further questions.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ian
Top achievements
Rank 1
answered on 08 Aug 2014, 06:53 PM
Thanks again Stef! UriReportSource did the trick, as you are saying. I am calling the below C# method in my MVC controller from a Razor Html.ActionLink in my view:

public ActionResult ExportReport()
{
    Telerik.Reporting.Processing.ReportProcessor reportProcessor =
        new Telerik.Reporting.Processing.ReportProcessor();
 
    System.Collections.Hashtable deviceInfo =
        new System.Collections.Hashtable();
    deviceInfo.Add("DocumentAuthor", User.Identity.Name);
 
    Telerik.Reporting.UriReportSource uriReportSource =
        new Telerik.Reporting.UriReportSource();
    uriReportSource.Uri = Server.MapPath("~/MyFolder/MyReport.trdx");
 
    Telerik.Reporting.Processing.RenderingResult result =
        reportProcessor.RenderReport("DOCX", uriReportSource, deviceInfo);
 
    string fileName = result.DocumentName + "." + result.Extension;
    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    string filePath = System.IO.Path.Combine(path, fileName);
 
    using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
    {
        fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
    }
 
    return RedirectToAction("Index");
}
Dhaval
Top achievements
Rank 1
commented on 26 Jul 2022, 10:51 AM | edited

Hi Stef,

As I can see that above solution works absolutely perfect as per the requirement but when you are not passing the parameters,

but in my case when I am passing the parameters then 

Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", uriReportSource, deviceInfo);

is not working

Below are two ways I had used with Object value

object PurchaseId1 = PurchaseId;
                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("PurchaseId", PurchaseId1));

Without object

                        uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("PurchaseId", PurchaseId));

 

but unfortunately the result is same every time and I am not able to generate PDF.
Can anyone please help me in this case?

 


Neli
Telerik team
commented on 29 Jul 2022, 06:41 AM

Hi Dhaval,

The configuration seems correct to me, In general the way to set parameter's values is:

var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();

var reportSource = new Telerik.Reporting.UriReportSource();
reportSource.Uri = reportName;


// Pass parameter value with the Report Source if necessary
object parameterValue = "Some Parameter Value";
reportSource.Parameters.Add("ParameterName", parameterValue);
I suspect that the root of the issue might be different. For that reason, I would recommend sending us a sample runnable application that reproduces the problem, so I can inspect it on my end.

Dhaval
Top achievements
Rank 1
commented on 10 Aug 2022, 06:30 AM

Hi Neli,

Please accept my apologies for replying late,

Sure I can send you runnable sample please let me know how can I send it to you?

Like from An email or any other resources?

Thanks

Dhaval
Top achievements
Rank 1
commented on 10 Aug 2022, 07:26 AM | edited

Hi Neli,

This is not required now, I got a solution of it the problem was that my parameters were Guid which I was not converting to string while passing it as a Report Parameter.

So bottom line is that in object any one need to convert parameter to string.

Thanks for your support appreciate it.

Tags
Report Designer (standalone)
Asked by
Ian
Top achievements
Rank 1
Answers by
Stef
Telerik team
Ian
Top achievements
Rank 1
Share this question
or