
Hi,
We are starting to use the Reporting Web Designer. We need to implement custom report storage as explained here: https://docs.telerik.com/reporting/how-to-implement-a-report-definition-storage
This method: public byte[] GetDefinition(string definitionId) { // Retrieve the report definition bytes from the database. } needs to return byte array of the report.
I have tried converting the report object to byte[] using serialize as shown here https://stackoverflow.com/questions/4865104/convert-any-object-to-a-byte/45402065. But it says that Report object is not serializable.
System.Runtime.Serialization.SerializationException: 'Type 'Telerik.Reporting.Report' in Assembly 'Telerik.Reporting, Version=14.0.20.219, Culture=neutral, PublicKeyToken=a9d7983dfcc261be' is not marked as serializable.'
Is there any specific byte[] serializers available with your API? I see there is ReportXmlSerializer to convert it to xml.
Thanks,
6 Answers, 1 is accepted
Hi Mirzodaler,
Consider the following implementation of the method GetDefinition using the ReportPackager we provide:
public byte[] GetDefinition(string definitionId)
{
var reportInstance = new BarcodesReport();// select the report based on the received 'definitionId'
var reportPackager = new ReportPackager();
using (var targetStream = new MemoryStream())
{
reportPackager.Package(reportInstance, targetStream);
return targetStream.ToArray();
}
}
See also Package Report Definition article.
Regards,
Todor
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.

Hi Todor,
Thank you for the solution. I am getting following error in a web designer after implementing custom definition:
Could not open report 'TEST_PERSONLISTREPORT.TRDX'. Error: An error has occurred. Data at the root level is invalid. Line 1, position 1.
For more detailed error see an image in an attachment.
Is FileDefinitionStorage implementation for byte[] GetDefinition is similar as you have provided in a solution? Or can you provide with a source code of FileDefinitionStorage?
Thank you,
Hello Mirzodaler,
Indeed, when you select a file name with extension TRDX from the list, it will be treated as such, and the Web Report Designer will attempt to utilize the byte[] as a TRDX report definition. The sample implementation returns byte[] of a TRDP report definition, hence the error. So, you need to provide the list of reports with extensions 'TRDP'.
Alternatively, you may use the ReportXmlSerializer to obtain the byte[] for the TRDX reports.
Regards,
Todor
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.

Hi Todor,
I am still having the same problem and I am aware of trdp and trdx should be loaded differently. I have following code to process public byte[] GetDefinition(string definitionId) - for trdx:
var reportPackager =
new
ReportPackager();
using
(var targetStream =
new
MemoryStream())
{
Report reportFile;
using
(var sourceStream = System.IO.File.OpenRead(
"C:\\Users\\Mirzodaler\\Desktop\\test-report.trdx"
))
{
ReportXmlSerializer xmlSerializer =
new
ReportXmlSerializer();
reportFile = (Telerik.Reporting.Report)xmlSerializer.Deserialize(sourceStream);
reportPackager.Package(reportFile, targetStream);
return
targetStream.ToArray();
}
}
Similar for trdp:
var reportPackager =
new
ReportPackager();
using
(var targetStream =
new
MemoryStream())
{
Report reportFile;
using
(var sourceStream = System.IO.File.OpenRead(
"C:\\Users\\Mirzodaler\\Desktop\\ForReportStorage2.trdp"
))
{
reportFile = (Telerik.Reporting.Report)reportPackager.Unpackage(sourceStream);
reportPackager.Package(reportFile, targetStream);
return
targetStream.ToArray();
}
}
Can you provide a full solution for this?
The error is still the same: Error: An error has occurred. Data at the root level is invalid. Line 1, position 1. at StorageService._callee2$
Thank you,
Hi Mirzodaler,
In the code for TRDX files, you still use the ReportPackager that is suitable only for TRDP reports.
Here is sample code for creating byte[] for both TRDX and TRDP report definitions:
public byte[] GetDefinition(string definitionId)
{
var reportInstance = new BarcodesReport();// create the necessary report instance
var extension = Path.GetExtension(definitionId);
if (extension == ".trdp")
{
return this.GetZipBytes(reportInstance);
}
return this.GetXmlBytes(reportInstance);
}
private byte[] GetXmlBytes(BarcodesReport reportInstance)
{
using (var targetStream = new MemoryStream())
{
ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
xmlSerializer.Serialize(targetStream, reportInstance);
return targetStream.ToArray();
}
}
private byte[] GetZipBytes(BarcodesReport reportInstance)
{
using (var targetStream = new MemoryStream())
{
var reportPackager = new ReportPackager();
reportPackager.Package(reportInstance, targetStream);
return targetStream.ToArray();
}
}
Todor
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.

@Tommy, yes, the answer provided by Todor and marked as accepted solved our issue.
Thanks,