Hello, I am new to Telerik. I want to have a button in my ASP.NET MVC web application that when clicked:
- executes a .trdx standalone Telerik file
- 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
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.
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?
The AssemblyQualifiedName of an object is a string structured as follows:
<
full_namespace
>.<
type_name
>, <
assembly_name
>
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.
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"
);
}
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?
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);
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
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.