Hi,
I'm currently using the Telerik Report viewer in React. It works fine when displaying the report, but I encounter an issue when trying to export the report. Upon attempting to export, it redirects me to the following route:
http://localhost:5000/api/reports/clients/32a9a544f84/instances/bf7cdf0ed6c/documents
This route isn't configured in the routing setup, leading to a subsequent redirection to a 404 error page.
3 Answers, 1 is accepted
I Have Solved the Issue by Creating the Route That Report viewer redirect and downloading the report
downloadReportAPI: (clientId: string, instanceId: string, documentId: string) =>
axios.get<any>(
`/reports/clients/${clientId}/instances/${instanceId}/documents/${documentId}?response-content-disposition=attachment`
),
import React, { useEffect, useState } from 'react';
import { useNavigate, useParams, useLocation, Navigate } from 'react-router-dom';
import { observer } from 'mobx-react-lite';
import { useStore } from 'src/stores/store';
export default observer(function DownloadReport() {
const { clientId, instanceId, documentId } = useParams();
const { pathname } = useLocation();
const [loading, setLoading] = useState(false);
const [text, setText] = useState('....');
const navigate = useNavigate();
const {
ReportStore: { downloadReport, loadingList },
} = useStore();
const downloadFile = async (response: any) => {
setLoading(true);
setText('Downloading....');
if (!response || !response.blob) {
console.error('Invalid response:', response);
return;
}
try {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = documentId!; // Set a more meaningful file name if needed
document.body.appendChild(a);
a.click();
a.remove();
setLoading(false);
} catch (err) {
console.error('Error while processing the response:', err);
}
};
useEffect(() => {
const res = downloadReport(clientId!, instanceId!, documentId!);
downloadFile(res);
}, [downloadReport]);
// useEffect(() => {
// downloadFile();
// }, [clientId, instanceId, documentId]);
if (loading) return <h1>{text}</h1>;
return null;
});
Hello Arifullah,
Indeed, the Resolve Document Request is sent when the report viewer attempts to render a report to one of the available rendering formats. However, this request is not used exclusively by the export functionality. The interactive preview of the viewer requests an HTML5 rendering of the report using the same endpoint. Thus, if this endpoint of the service is inaccessible I would not expect the viewer to work at all.
Can you try connecting one of our demo report viewers to your Reporting REST Service (http://localhost:5000/api/reports) and let me know if the issue persists? For example, you can access our HTML5 Report Viewer Integration demo from the following solution.
C:\Program Files (x86)\Progress\Telerik Reporting <YOUR VERSION>\Examples\CSharp\CSharp.ReportExamples.VS2022.sln
If the error is reproducible with a different viewer, the issue is most likely within the service. In this case, I can suggest the following.
- Go through the manual configuration steps of the service and ensure everything is set up accordingly.
- Enable tracing and record a trace listener log of the issue.
Alternatively, if the error occurs only when you use the React Report Viewer, please send a runnable sample I can use to reproduce this locally and I will let you know what I find.
Kind Regards,
Momchil
Progress Telerik
Hi
<TelerikReportViewer
ref={(el: any) => (viewer = el)}
serviceUrl={url}
authenticationToken={token}
reportSource={{
report: reportName,
parameters: {
Parameter1: JSON.stringify(data),
Parameter2: reportParams,
},
}}
viewerContainerStyle={{
position: 'absolute',
left: '5px',
right: '5px',
top: '50px',
bottom: '5px',
overflow: 'hidden',
clear: 'both',
fontFamily: 'ms sans serif',
}}
viewMode="INTERACTIVE"
scaleMode="SPECIFIC"
scale={1.0}
enableAccessibility={false}
/>
using Telerik.Reporting.Services;
using Telerik.Reporting.Services.AspNetCore;
namespace API.Controllers
{
[Route("api/reports")]
[ApiController]
public class ReportsController : ReportsControllerBase
{
public ReportsController(IReportServiceConfiguration reportServiceConfiguration)
: base(reportServiceConfiguration)
{
}
}
}
I am passing the data to report through Parameter1: JSON.stringify(data)
it's the same in all reports when I click on export to PDF or Excel it redirects to another page
I want the report viewer not to redirect and download the report
Hi Arifullah,
Thank you for sharing your setup.
The configuration of the viewer and the reports controller looks valid. Still, the routing settings of the application can block some of the endpoints of the Reporting REST Service.
Did you check if connecting the viewer to a different Reporting REST Service resolved the export issue? If you do not have the examples I mentioned, you can also use our public demos API (https://demos.telerik.com/reporting/api/reports) to test. For example, you can make the following changes to your viewer to preview the Dashboard report from our demos.
<TelerikReportViewer
serviceUrl="https://demos.telerik.com/reporting/api/reports"
reportSource={{
report: "Dashboard.trdx"
}}
...
/>
If you can successfully export the Dashboard report from our demos, we need to test the application that hosts your Reporting REST Service. To do that, please record the trace listener log I mentioned in my previous reply.
Regards,
Momchil
Now I'm getting the following error
The version of the Report Viewer '17.1.23.718' does not match the version of the Reporting REST Service '18.1.24.514'. Please make sure both are running the same version.
Hi Arifullah,
Indeed, the versions of the viewer and the service need to match.
Earlier I forgot to mention that our demos use the 18.1.24.514 version. Apologies for the oversight.
If you do not wish to update your viewer to 18.1.24.514, you can run the attached REST Service project instead and point the viewer to it.
<TelerikReportViewer
serviceUrl="http://localhost:59655/api/reports"
reportSource={{
report: "SampleReport.trdp"
}}
...
/>
Hi
I Run Your Reporting Services Project and Connected my Report viewer From my app. It is ok and there is no redirect to another page
but here only pass a report name
<TelerikReportViewer
serviceUrl="http://localhost:59655/api/reports"
reportSource={{
report: "SampleReport.trdp"
}}
...
/>
and I pass the data through parameters to report also
serviceUrl={url}
authenticationToken={token}
reportSource={{
report: reportName,
parameters: {
Parameter1: JSON.stringify(data),
Parameter2: reportParams,
},
}}