This is a migrated thread and some comments may be shown as answers.

Picturebox with Image url not working in multiple projects

2 Answers 642 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Hari
Top achievements
Rank 1
Hari asked on 02 May 2019, 09:44 AM

I have a Telerik Reporting Library 2019 project which contains Telerik Reports. The reports are consumed from a ASP.NET Core web application when controller actions are called. So there is a reference to this Reporting library project from Web project.

In the web project I create a ReportBook to generate report. and render the report as a PDF.

[HttpGet("{reportId}", Name = "Report")]
public async Task<IActionResult> Get(Guid reportId)
{
    //Report Book
    var reportBook = new ReportBook();
    var instanceReportBookSource = new InstanceReportSource
    {
        ReportDocument = reportBook
    };
 
    //Cover Page
    var coverPageReportSource = new InstanceReportSource();
    var coverPagereport = new CoverPage(reportId)
    {
        DocumentName = "Cover Page Report"
    };
    coverPageReportSource.ReportDocument = coverPagereport;
    reportBook.ReportSources.Add(coverPageReportSource);
 
    var reportProcessor = new ReportProcessor();
    var renderingResult = reportProcessor.RenderReport("PDF", instanceReportBookSource, new Hashtable());
 
    var fileName = renderingResult.DocumentName + "." + renderingResult.Extension;
    var path = Path.GetTempPath();
    var filePath = Path.Combine(path, fileName);
 
    using (var fs = new FileStream(filePath, FileMode.Create))
    {
        fs.Write(renderingResult.DocumentBytes, 0, renderingResult.DocumentBytes.Length);
    }
 
    var output = renderingResult.DocumentBytes;
    return File(output, "application/pdf");
}

 

 In the reports I have few PictureBox components. I want to set pictures from a http url (https://docs.telerik.com/reporting/report-items-picture-box#data-binding)

Example

1.var pictureBox = ((Telerik.Reporting.PictureBox)(reportDef.Items.Find("pictureBox1", true)[0]));
2.pictureBox.Value = "https://d585tldpucyb98b4-413e94c0e92bvanemkallan.jpg"; //Some Image URL

 

But when I try to do that it always gives an error (report-error.png). Is this because I have report definition in one project and consuming it from another project (web project). How can I solve this.

 

 

 

2 Answers, 1 is accepted

Sort by
0
Hari
Top achievements
Rank 1
answered on 02 May 2019, 10:17 AM
0
Todor
Telerik team
answered on 07 May 2019, 09:32 AM
Hello Hari,

Such an error will appear when there is no value set to the PictureBox item (note that the value is an empty string "").
From the provided information I assume that in the report definition pictureBox1 has no default value, and the image URL is set to the item definition (i.e. Telerik.Reporting.PictureBox) in the code.
When this is done in the constructor of the report, right after the call to InitializeComponent() method the value should be respected and the image should be displayed.
If this is done in a Report event it may not work, as it may be too late. I tested locally, and the code for setting the PictureBox image worked when used in the ItemDataBinding and NeedDataSource events of the Report, and threw the same error message when used in the ItemDataBound event (this is the last report event that is raised).
For more details you may check the Changes on items in report events are not applied KB article.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Hari
Top achievements
Rank 1
Answers by
Hari
Top achievements
Rank 1
Todor
Telerik team
Share this question
or