Report Help: Display image from server location
This is a report question. I wasn't sure where to post
I want to display an image (that is sitting on a server in my organization) in a report. I have a script that generates a correct file path to the image. I know the path is correct because I can past it into a browser and have the image open. Based on my research. The best way to display an image using a file path is to use a RichTextBox and some scripting.
The script below generates a complete working file path but instead of an image showing in the RichTextBox. I only see the file path. The HTML tags do not appear to be rendering. Can anyone point me in the right direction.
public void Detail1_Format()
{
RichTextBox RichTextBox1 = rpt.Sections["Detail1"].Controls["RichTextBox1"] as RichTextBox;;
string fn = rpt.Fields["fileName"].Value as String; //this is the name of the image
string linkURL =( "http://gis6.midland-mi.org/propPhotos/" + fn); //this generates the complete file path
string lu = "<img src='" + linkURL + "'></img>";
RichTextBox1.Text = lu;
RichTextBox1.Html = RichTextBox1.Text;
}
Thanks in advance
Dan Brumm
GIS Coordinator
City of Midland MI
-
Hi Daniel,
You want an image control instead of a rich textbox to show an image.
Here is the script in the RPX file found in the code gallery at https://support.geocortex.com/la-county-parcel-report
public void detail_Format()
{
try {
string imageUrl = String.Format("http://maps.googleapis.com/maps/api/streetview?size=400x400&location={0} {1}&sensor=false"
, rpt.Fields["SITEADDRESS"].Value.ToString()
, rpt.Fields["SA_CITYSTATE"].Value.ToString() );
System.Net.WebClient client = new System.Net.WebClient();
System.IO.Stream stream = client.OpenRead(imageUrl);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
stream.Flush();
stream.Close();
Picture streetView = (Picture)rpt.Sections["detail"].Controls["StreetView"];
streetView.Image = (Image)bitmap;} catch {}
}In the 4.2 LA County sample site, the example changed to use a transformation workflow. Watch http://support.geocortex.com/report-dataset-transformation-workflows to get started with this method.
regards,
Edmond0 -
Edmond
Thank for the reply. What I found out was that my code was fine. I moved it from the Details_Format() event into the Details_BeforePrint() event and it worked perfectly. My guess is that the report was redering before the script could retrieve the image.?? Just thought I would post an update. Thanks again.
Dan
0 -
Daniel,
Thank you for posting your code example. I was able to get it to work for our setup. However, I'm trying to handle a 1-to-many relationship, with the report capable of handling multiple images, and I've not been able to adapt the code in a sub report to dynamically update a new picture (it duplicates the first picture)...Any thoughts?
Faron0
Please sign in to leave a comment.
Comments
3 comments