PictureBox error if image not found

7 posts, 0 answers
  1. Hans Werner
    Hans Werner avatar
    3 posts
    Member since:
    Oct 2009

    Posted 19 Nov 2009 Link to this post

    Hello Telerik Team,
    i'm evaluating your great reporting product, but i have some little problems and i hope to find some help here.

    I've draged a PictureBox into my report (detail section) and made the following Expression to load a harddrive stored picture into it:

    = Format("C:\ProductPictures\{0}.jpg", Fields.articleNo) 

    This is working perfectly as long as the picture with the filname "articleNo+.jpg" exists in the given harddrive folder. If there isn't a picture for the specific article (which is a common situation for our needs), i get the following error in the report output (for every not existing picture in a list with 5000 articles ...): 
    "An error has occured while processing PictureBox "pictureBox1': The File "C:\ProductPictures\ART00001.jpg" could not be found."

    Is there a way to supress the error message if the picture doesn't exists? We don't need and want this error message =)

    Best Regards from Germany
    Hans
  2. Hans Werner
    Hans Werner avatar
    3 posts
    Member since:
    Oct 2009

    Posted 19 Nov 2009 Link to this post

    No ideas for solving this problem?
  3. DevCraft banner
  4. Hans Werner
    Hans Werner avatar
    3 posts
    Member since:
    Oct 2009

    Posted 19 Nov 2009 Link to this post

    Here a possible solution for everyone lookin for:

    Make a user function:
    public static String PicturePath(String sCompletePath) 
            { 
                String sFinalPath = ""
     
                if (File.Exists(sCompletePath)) 
                    sFinalPath = sCompletePath; 
                else 
                { 
                    String sCurrentAppDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); 
                    sFinalPath = sCurrentAppDirectory + "\\default.jpg"
                } 
     
                return sFinalPath; 
            } 

    In the picturebox expression, extend the statement from
    = Format("C:\ProductPictures\{0}.jpg", Fields.articleNo)  
    to
    = TelerikReportTutorial.ArticleList.PicturePath(Format("D:\Work\OBI\Artikel-Bilder\{0}.jpg", Fields.articleNo)) 

    And everything works fine. You just need to create a 1x1 pixel default.jpg image in your app directory which will be used if the other picture doesn't exist.

    Have fun!








  5. Rafa
    Rafa avatar
    11 posts
    Member since:
    Aug 2014

    Posted 15 Jan 2015 Link to this post

    Hi,

    Is there any official solution for this yet?

    Regards,
    Rafa
  6. KS
    KS avatar
    165 posts
    Member since:
    Oct 2012

    Posted 20 Jan 2015 in reply to Rafa Link to this post

    Hi,

    User functions do the work for me and let me check if the image exists on the server. Maybe you are searching for some error handling like with Report.Error event.

    -KS
  7. Rafa
    Rafa avatar
    11 posts
    Member since:
    Aug 2014

    Posted 11 Feb 2015 in reply to KS Link to this post

    Hi KS,

    Yes, currently I am using user function similar to Hans Werner's post above. But I wonder if  a built in function for this will be available sooner or later.

    Regards, 
    Rafa
  8. KS
    KS avatar
    165 posts
    Member since:
    Oct 2012

    Posted 16 Feb 2015 in reply to Rafa Link to this post

    Hi,

    Sounds like a feature request. I think this is a matter of error handling (to have a missing image is an unexpected behavior resulting in an error) and there is no common solution. Sometimes it is better to have a default image instead of a blank space or broken image. Sometimes blank space is the expected result.

    -KS
Back to Top
DevCraft banner