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

Reporting Error when setting Picturebox.Value dynamically: "Could not find a part of the path"

9 Answers 682 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
AN
Top achievements
Rank 1
AN asked on 20 Aug 2017, 04:01 PM

We have an ASP.NET web app running on .Net 4.6.1 which uses Telerik Reporting extensively to create PDFs. We have just updated our Telerik Reporting library fro 2014 to 2017 (tried all versions).

We have a number of "PictureBox" elements in our PDF reports where we generate an image in code and assign that to the PictureBox's Value element (snippet below).

 

1. Report designer code for the PictureBox:
---------------------------------------------------------
this.pictureBox6 = new Telerik.Reporting.PictureBox();
this.pictureBox6.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.47999998927116394D), Telerik.Reporting.Drawing.Unit.Inch(2.2999999523162842D));
this.pictureBox6.MimeType = "";
this.pictureBox6.Name = "pictureBox6";
this.pictureBox6.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(2.2899999618530273D), Telerik.Reporting.Drawing.Unit.Cm(2.2899999618530273D));
this.pictureBox6.Sizing = Telerik.Reporting.Drawing.ImageSizeMode.ScaleProportional;
this.pictureBox6.Style.BackgroundColor = System.Drawing.Color.Transparent;
this.pictureBox6.Value = "";



2. Create a Bitmap image dynamically and assign to the PictureBox element:
-----------------------------------------------------------------------------------------------------

var flag = new System.Drawing.Bitmap(10, 10);
for (int x = 0; x < flag.Height; ++x)
    for (int y = 0; y < flag.Width; ++y)
        flag.SetPixel(x, y, Color.White);
for (int x = 0; x < flag.Height; ++x)
    flag.SetPixel(x, x, Color.Red);

var image = flag;

pictureBox6.Value = image; // RUNTIME ERROR BELOW:

"An error has occurred while processing PictureBox 'pictureBox6':
Invalid image data.
------------- InnerException -------------
Could not find a part of the path 'D:\DEV\MyProj\MyProj.Web\'.

 

I have tried the following already:

- var image = Image.FromFile("D:\\DEV\\MyProj\\MyPorj.Web\\Content\\Images\\5.PNG");
  pictureBox6.Value = image;

- MemoryStream ms = new MemoryStream();
   image.Save(ms, ImageFormat.Bmp);
   pictureBox6.Value = image;

 

Both of the above return the same error. For the life of me, I can't figure out the cause of this error. Downgrading back to Telerik Reporting 2014 fixes the problem. Please help.

9 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 21 Aug 2017, 11:51 AM
Hi AN,

We tried to reporoduce the problem with the MVC-project you can find attached. We set the PictureBox value either in the Constructor of the or using a DataBinding event (which is an erroneous approach). In both the report was displayed correctly.
I would ask you to open the attached project and try to introduce changes that would replicate the issue. This way we would be able to investigate it further.


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
0
AN
Top achievements
Rank 1
answered on 22 Aug 2017, 07:07 AM

Hi Todor,

Thanks for this but are you able to provide a simple example in plain ASP.NET Web forms (not MVC)? Also, we are NOT using Telerik Report Viewer. We generate a PDF directly and download it to the client's machine. Are you able to quickly come up with such a sample project and attach it here?

I have just inherited a large project with a lot of PDFs being generated using Telerik Reporting. I am struggling to create a simple as possible project to reproduce the issue. So if you could please provide me with a simple solution as described above with a PictureBox.Value being set in code, I will have a play with it and let you know.

 

Thanks.

0
Todor
Telerik team
answered on 22 Aug 2017, 12:24 PM
Hello AN,

Please, find attached the required WebForms Application. It will both show the report (with the PictureBox with value set in the code) in the ReportViewer, and automatically export it programatically in PDF. The exported file could be found in the main project folder (...\WebFormsApplication\WebformsApplication\Report1.pdf) after running the application.

I hope this will help. Looking forward to assist you further.

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
0
AN
Top achievements
Rank 1
answered on 27 Aug 2017, 12:24 PM

Hi Todor/Admin,

Thanks for the sample. After experimenting with it a bit, I have realised that my problem was not with the PictureBox. It was in fact the ReportParameters that were not being handled correctly by the report.

In the project you provided me, I have modified the code a little to add a ReportParameter to the Report. This parameter is then used to set the value of a Textbox object. It fails.I realise I am using "InstanceReportSource" which is not recommended anymore. However I would like to continue using this in the short-term as we have dozens of reports and we do not have the time to upgrade them all to use the new "TypeReportSource" class.

Please help. Thanks.

P.S: I am trying to attach a zip of the solution but I get: " Suspicious content has been detected by our anti-spam service. Try to revise your post or submit it for review. "
0
AN
Top achievements
Rank 1
answered on 27 Aug 2017, 12:29 PM

Ah, turns out I can't attach solutions. Here is the code that I added:

Default.aspx.cs

---------------------

rivate void Export(string exportFormat)
        {
            this.path = AppDomain.CurrentDomain.BaseDirectory;
            this.deviceInfo = new Hashtable();
            this.reportProcessor = new ReportProcessor();
            this.typeReportSource = new TypeReportSource();
            this.typeReportSource.TypeName = "WebFormsApplication.Report1, WebFormsApplication";

            Telerik.Reporting.Report report1 = new Report1();
            report1.ReportParameters[0].Value = "testing 1 2 3 4";
            
            Thread thread = new Thread(() =>
            {
                RenderingResult renderResult = reportProcessor.RenderReport("PDF", new InstanceReportSource { ReportDocument = report1 }, deviceInfo);
                string fileName = $"{renderResult.DocumentName}.{renderResult.Extension}";
                string filePath = Path.Combine(this.path, fileName);

                using (FileStream fs = new FileStream(filePath, FileMode.Create))
                {
                    fs.Write(renderResult.DocumentBytes, 0, renderResult.DocumentBytes.Length);
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }

 

Report1.cs
---------------
    public void SetTextBox1Value()
        {

           // added a TextBox control on the report and named it textBox1
            textBox1.Value = ReportParameters[0].Value.ToString();
        }

        private void Report1_NeedDataSource(object sender, EventArgs e)
        {
            this.PictureBox6SetValue();
            this.SetTextBox1Value();
        }

 

PROBLEM: The " ReportParameters[0].Value" has null instead of the value I intended.     

0
Todor
Telerik team
answered on 28 Aug 2017, 11:54 AM
Hi AN,

Zip-files cannot be attached from the Forum. If you want to send us file, it would be necessary to open a ticket.

Note also that although the InstanceReportSource is legacy and not recommended, it is functional, and I don't think it would be necessary to upgrade your reports to use the TypeReportSource class.

We modified the sample solution according to the provided code. In the Export method the value of the Parameter is set to "testing 1 2 3 4". This value should appear in the exported PDF since it calls this Export method. If the text doesn't appear, I would ask you to open a ticket and send the solution for further investigation.
Note that when loading the report in the ReportViewer, method Export is not called, and there is no value explicitly assigned to the Parameter. Therefore, the Value property assigned in Designer is used, and by default it is null.
I would suggest you to add a (default) value to the Paremeter in the Designer, or in the Report1 class constructor.

Hopefully this explanation helps. Let us know if you have more questions.

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
0
AN
Top achievements
Rank 1
answered on 29 Aug 2017, 04:36 PM

Thanks for the explanation about the Export method not being called in the Reportviewer. I was actually looking at that wondering why it wasn't working. The PDF creation and download from .aspx.cs works perfectly fine.

However, in my project, the Report Parameters are still acting strange. In my Report.cs, I can see the ReportParameters[] array populated with all the parameters I expected. But these parameters are not printed in the report when it is downloaded as pdf. Strange thing is if I change the Telerik Reporting dll reference back to 2014, the code works fine again.

Can you think of another reason or is it best I raise a ticket? I'm not sure if I'm able to raise a ticket on this trial licence?     

0
Accepted
Todor
Telerik team
answered on 01 Sep 2017, 01:14 PM
Hi AN,

From the modification in the sample code we infer that you apply item changes in events. Note that in Telerik Reporting versions prior to R3 2016, all changes in events were accepted, whereas from R3 2016 each definition item property values are read and cached once the report rendering starts. Therefore, if you are working with item definitions in events, they will not be modified. This could explain why changing the Telerik Reporting dll reference back to 2014 resolves the issue.

I hope the referred KB article would be helpful. If the problem persists, or you have other questions, I would ask you to open a ticket and send us the report for further investigation.

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
0
AN
Top achievements
Rank 1
answered on 04 Sep 2017, 11:32 AM

Hi Todor,

Yes, that's exactly what my problem was. Thanks for providing the work-around at the end of the KB article. I was able to disable the caching mechanism in my config and that restored all our reports to their formal glory. Thanks for your help.

Cheers,

AN     

Tags
General Discussions
Asked by
AN
Top achievements
Rank 1
Answers by
Todor
Telerik team
AN
Top achievements
Rank 1
Share this question
or