How to pass an image to report from code?
Posted: Mon Jan 29, 2018 7:24 pm
Hello, I'm trying to populate and render a report with an image coming from a dynamic source, in an ASP.NET Core controller, but I don't know how to pass the image to the report, neither as a parameter nor as variable.
I've tried this:
1) In the dictionary I create a new variable (image type) called "Logo"
2) In the .mrt report I insert an image an set its source to an "Expression":
3) Then, in the controller:
But it doesn't work, it shows nothing... What's the correct way to pass an image to a report as an stream or something similar (image comes from a secured source, so it cannot come from an url or file path)
Thanks in advance
I've tried this:
1) In the dictionary I create a new variable (image type) called "Logo"
2) In the .mrt report I insert an image an set its source to an "Expression":
Code: Select all
{Logo}
Code: Select all
var fi = env.ContentRootFileProvider.GetFileInfo($@"\Images\logo1.png");
if (fi.Exists)
{
FileStream stream = new FileStream(fi.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);
report.Dictionary.Variables["Logo"].ValueObject = Image.FromStream(stream);
return StiNetCoreReportResponse.ResponseAsPdf(report);
}
else return BadRequest();
Thanks in advance