Picturebox binding issue

1 Answer 81 Views
General Discussions
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
Tursunkhuja asked on 13 Jul 2022, 08:56 AM

We want to show company logo in the picturebox element. Company logo file path can be programmatically changed. For this purpose, we created CompanyLogo parameter in the report and the picturebox has binding with this parameter's value to set file path to the picturebox's value. Sometimes, company can be without logo. If company doesn't have logo, we want the picturebox to show nothing.

Problem here is if we bind the picturebox with the report parameter, it shows an error if the file path doesn't exist or empty:

  

If the parameter's value is empty then the picturebox show empty space, instead of the error. As an example, if you remove binding and keep picturebox's value blank then it will show empty space.

Any solution or workaround for this problem?

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 18 Jul 2022, 08:12 AM

Hi Tursunkhuja,

You need to check whether the image file exists, and assign the PictureBox.Value 'Null' if it doesn't. This way, you will avoid the error. Here is a sample expression that assumes that you have implemented the MyFileExists function that checks whether the image file exists:

= IIF(MyFileExists(Parameters.CompanyLogo.Value), Parameters.CompanyLogo.Value, Null)

If you have the absolute path to the image, you may use the System.IO.File.Exists(string) method in the 'mscorlib.dll' assembly. Note that it will be necessary to register the assembly in the Standalone Designer as explained in the Extending Report Designer article.

If you would like to use images located in the folder with the reports, you may need to create a custom user function to check whether the image file exists.

In the case the image paths are relative to the application, i.e. the designer's folder when using the Standalone Designer, you may use the "System.AppDomain.GetDefaultDomain().BaseDirectory" property that returns the application base folder to calculate the absolute path to the image and use the File.Exists(string) method.

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
General Discussions
Asked by
Tursunkhuja
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Todor
Telerik team
Share this question
or