Saxophonist
Saxophonist

Reputation: 707

Print out RDLC of ReportViewer as an image format

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:

enter image description here

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

Answers (2)

Anil Ghildiyal
Anil Ghildiyal

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

Saxophonist
Saxophonist

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

Related Questions