Hi, is it possible to set a repportviewer from bytearray ?
here is my service :
public class ReportServiceManager
{
private LocalReport Report;
public byte[] RenderToPdf()
{
string templateName = "Reporting.Common.ReportTemplates.MyReport.rdlc";
Report.SetTemplate(templateName, null);
// set parameters
// ....................
// Set datasources
// ....................
string mimeType, encoding, fileNameExtension;
string[] streams;
Warning[] warnings;
return Report.Render("PDF", GetPdfDeviceInfo(), out mimeType,
out encoding, out fileNameExtension, out streams, out warnings);
}
protected string GetPdfDeviceInfo()
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + "id" + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
return deviceInfo;
}
}
So on my aspx page I do as follow :
ReportServiceManager ReportServiceManager = new ReportServiceManager();
var reportdata = ReportServiceManager.RenderToPdf();
MemoryStream ms = new MemoryStream(reportdata);
ReportViewer1.LocalReport.LoadReportDefinition(ms);
ReportViewer1.DataBind();
So my reportservice returns a byte[] and I want to use it to populate my report viewer
private void CreatePDF(string fileName)
{
// Setup DataSet
MyDataSetTableAdapters.YourTableAdapterHere ds = new MyDataSetTableAdapters.YourTableAdapterHere();
// Create Report DataSource
ReportDataSource rds = new ReportDataSource("MyDataSourceName", ds.GetData());
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "YourReportHere.rdlc";
viewer.LocalReport.DataSources.Add(rds); // Add datasource here
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
}
Member
11 Points
7 Posts
Set LocalReport of reportviewer from byte[]
Sep 18, 2016 08:35 PM|Olivier DUBOIS|LINK
Hi, is it possible to set a repportviewer from bytearray ?
here is my service :
So on my aspx page I do as follow :
So my reportservice returns a byte[] and I want to use it to populate my report viewer
Best regards
All-Star
17652 Points
3510 Posts
Re: Set LocalReport of reportviewer from byte[]
Sep 19, 2016 01:33 PM|Chris Zhao|LINK
Hi Olivier,
Take a look at this thread, you could try this
Best Regards,
Chris
Member
11 Points
7 Posts
Re: Set LocalReport of reportviewer from byte[]
Sep 19, 2016 08:18 PM|Olivier DUBOIS|LINK
Hi, thank for your reply but I do not want to send it to client for download.
I want the client to display it on a report viewer.
Best regards
All-Star
17652 Points
3510 Posts
Re: Set LocalReport of reportviewer from byte[]
Sep 28, 2016 09:31 AM|Chris Zhao|LINK
Hi Olivier,
Best Regards,
Chris