Reputation: 707
I need to export a report viewer RDLC as an image that might be any image format.
When a set the the output format as PNG or even JPEG I got expection, as below:
If I try as EMF it works out, but not for others formats as JPEG or PNG. Apart from that, How could I save this output image at the disk?
Thanks for the help!
Upvotes: 0
Views: 9866
Reputation: 11
Or you can also use the below code to download an image. or you can change your reportType to (pdf,word or excel) as well as the outputFormats to (pdf,doc,xls respectively) for exporting reports as pdf, word or excel.
string reportType = "Image";
string outputFormat = "jpg";
byte[] renderedBytes = report.Render(reportType, null);
/* Download File.....*/
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("ddMMyyyyhhmmss") + "." + outputFormat);
Response.BinaryWrite(renderedBytes);
Response.Flush();
Upvotes: 1
Reputation: 707
Could achieve the desired solution by the code below
var byts = report.Render("Image", "<DeviceInfo><OutputFormat>PNG</OutputFormat></DeviceInfo>");
File.WriteAllBytes("c:\\test.png", byts);
Upvotes: 3