Zum Hauptinhalt gehen

Scripting in Report Designer

Kommentare

5 Kommentare

  • Permanently deleted user

    It is pretty straight forward. I think the issue most people have is thinking that the Picture control will dynamically read an image from a URI. It won't, rather you have to read the Image from the URI manually, then apply that image to the Picture objects Image property.

     

    Code sample:

    public void Detail1_Format()

     

    {

     

        String imageFolder = "E:/Images/";

     

        String imagePath = null;

     

        

     

        if(rpt.Fields.Contains("IMAGENAME")){

     

            String imageName = Convert.ToString(rpt.Fields["IMAGENAME"].Value);

     

            imagePath = imageFolder + imageName;

     

            if(System.IO.File.Exists(imagePath)){

     

                    System.Drawing.Image theImage = null;

     

                    theImage =System.Drawing.Image.FromFile(imagePath);

     

        

     

                    Picture thePic = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;

     

                    thePic.Image = theImage;

     

            }

     

        }

     

    }

    Hope that helps.

    Jay

    0
  • Permanently deleted user

    Thanks Jason, 

     

    I tried that code but it pukes and says compile error on line 21 =; expected..

     

    any thoughts?

     

    public void Detail1_Format()

     

    {

     

      String imageFolder = "D:/Data_Client/YourTown/SidewalkInspection_Images/";

     

        String imagePath = null;

     

        

     

        if(rpt.Fields.Contains("lblFileName"))

     

        {

     

            String imageName = Convert.ToString(rpt.Fields["lblFileName"].Value);

     

            imagePath = imageFolder + imageName;

     

            if(System.IO.File.Exists(imagePath))

     

            {

     

                    System.Drawing.Image theImage = null;

     

                    theImage =System.Drawing.Image.FromFile(imagePath);

     

        

     

                    Picture thePic = rpt.Sections["Detail1"].Controls["Image1"] As Picture;

     

                    thePic.Image = theImage;

     

            }

     

        }

     

    }
    0
  • Permanently deleted user

    C# as operator is case sensitive.

    Change:  Picture thePic = rpt.Sections["Detail1"].Controls["Image1"] As Picture;

    To: Picture thePic = rpt.Sections["Detail1"].Controls["Image1"] as Picture;

     

    0
  • Permanently deleted user

    Good Morning,

    We have this script working in a similar fashion for a URL from a 3rd party that display's property photos.  What I was wondering is if anyone has a script method that will work with code similar to Jason's here to handle 404 exceptions.  For example if a user clicks on a parcel that does not have a current photograph of the property, the report throws an error due to the 404 or 500 return that the URL with the photo does not exist.  I haven't been able to get the correct format to run to grab these type of exceptions, replace the photo to display and move on to url's that are valid.  Any help would be appreciated.

    Thanks!

    Brian

     

     

     

    0
  • Berend Veldkamp

    The easiest way to work around these exceptions would be to use a try...catch block:

     

    try

    {

    // Get the picture

    }

    catch (Exception ex)

    {

    // Do nothing, maybe show a placeholder image, or text ex.Message

    }

     

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.