Skip to main content

Dynamic Images in Reports

Comments

7 comments

  • John Nerge

    Short answer: Yes.

    Long answer: It depends on where the images are stored and how they're linked to your feature ( e.g.  a separate database, field value, or feature attachment). Can you provide some more info?

    0
  • Permanently deleted user

    Thanks for the response.

    They are stored locally on one of our servers.

    Right now I have the name of the Image (jpg) as the value under a field.

    I can access the image no problem in the Feature Long Decription using the following:

    </p><p><img width="29" height="30" style="width: 194px; height: 164px;" src="http://exploreajax.ajax.ca/maps/ClientBin/Images/{ADDRESS}.jpg"></p><p><br></p>

    0
  • John Nerge

    I haven't pulled an image in like that before, but it seems like something you should be able to do in the Script tab of your report. 

    Since you have a partial path as your field value, you need to to calculate the full path on the fly. Here's a working example in one of my reports that assigns the hyperlink value to a label control I have. The result is that the report displays the parcel ID which links to its unique tax info page.

        Label hyperlink2 = rpt.Sections["Detail1"].Controls["PropInfo"] as Label;

     

        string pid = rpt.Fields["PID"].Value as string;

     

        hyperlink2.HyperLink = "http://www16.co.hennepin.mn.us/pins/pidresult.jsp?pid=" + pid;

     

     

    So, in theory, you should be able to do something like this for your image path.

        Image image1 = rpt.Sections["Detail1"].Controls["YourImageControl"] as Image;

     

        string address = rpt.Fields["ADDRESS"].Value as string;

     

        image1.Image = "http://exploreajax.ajax.ca/maps/ClientBin/Images/" + address + ".jpg";

     

     
    0
  • Permanently deleted user

    Hi John and Chris

    here is an example of a piece of working code in one of my reports:

            public void reportHeader_Format()

     

            {

     

                System.Net.NetworkCredential cred = new System.Net.NetworkCredential("user", "password", "domain");

     

                try

     

                {

     

                    string URL = Convert.ToString(rpt.Fields["urlMap"].Value);

                    //Setting up the image to retrieve webrequest

     

                    System.Drawing.Image pinImage = null;

     

                    System.Net.WebRequest req = System.Net.WebRequest.Create(URL);

     

                    req.Credentials = cred;

                    using (System.Net.WebResponse response = req.GetResponse())

     

                    using (System.IO.Stream stream = response.GetResponseStream())

     

                    {

     

                        pinImage = System.Drawing.Image.FromStream(stream);

     

                        String imgFileName = @"c:\temp\image" + System.DateTime.Now.Ticks.ToString() + System.DateTime.Now.Ticks.ToString() + ".jpg";

     

                        pinImage.Save(imgFileName);

     

                        Picture reportPicture1 = rpt.Sections["reportHeader"].Controls["Picture1"] as Picture;

     

                        Image image2 = Image.FromFile(imgFileName);

     

                        reportPicture1.Image = image2;

     

                    }

     

                }

     

                catch

     

                {

     

                }

     

            }

    Notes:

    • urlMap = attribute added to feature/graphic in FeatureSet being reported on that has an url to an image. In this case a map.
    • a header section called reportHeader has a Picture control in it called Picture1
    • the image is fetched from the 'remote' location to a 'local' location
    • not necessarily the best way to do this but it is working
    • I have a scheduled task to cleanup the 'local' location as well as other temporary file locations.

    Regards

    Ralph Price

    0
  • Permanently deleted user

    Thanks to both of you.

    I'll give your suggestions a shot

    0
  • Permanently deleted user
    John or Ralph,

     

    I'm trying to accomplish a similar objective, however in a 1-to-many relationship, making the report capable of displaying multiple images.  I'm adapting your code examples in a subreport, and I can get the initial picture to work, but it then duplicates the same photo in the sub report.  Any thoughts
    0
  • Permanently deleted user
    Hi Faron

     

    Where are you putting the Image? In the Detail section?

     

    If so then the code that I had above would be in somewhere like reportDetail_Format rather than reportHeader_Format.

     

    It sounds like your code is continuing to grab the first of the records rather than processing each related record with it's own source image.

     

    Does that make any sense?

     

    Regards

     

    Ralph Price
    0

Please sign in to leave a comment.