Adding a Hyperlink in a report
Hi all, I am struggling with this one.
I want to add a picture in a report based on the ID of the object that is selected for the report.
The pictures are stored under my website so can be accessed by a url. What I want to do is to have a box in the report in which the picture (Derived from the url and ID) is displayed
Has anybody done this please
Thanks
Chris
-
You can take the parcel.rpt that Geocortex provides and modify it so that it works with your data. To get that picture to show a photo from a web address, you add the following code to the script - you'll see on the bottom of report designer that there are 3 tabs - designer - script - preview - select the script tab.
Your detail section might be called something else like Detail1 but mine was called detail
public void detail_Format()
{
string pin_value = Convert.ToString( rpt.Fields["PIN"].Value);
string pictureUrl ="http://getMeMyPhoto.com/getbin.php?type=pic&parcel=" + pin_value;
//Setting up the image to retrieve webrequest
System.Drawing.Image pinImage = null;
System.Net.WebRequest req = System.Net.WebRequest.Create( pictureUrl );using( System.Net.WebResponse response = req.GetResponse() )
using( System.IO.Stream stream = response.GetResponseStream() )
{
pinImage = System.Drawing.Image.FromStream( stream );
}//PictureProperty is the name of the Picture control - your's might be a different name
Picture PictureProperty = rpt.Sections["detail"].Controls["PictureProperty"] as Picture;
PictureProperty.HyperLink = pictureUrl;
PictureProperty.DataField = pictureUrl;
PictureProperty.Image = pinImage;}
More info at Datadynamics forums: http://www.datadynamics.com/forums/85601/ShowPost.aspx
0 -
Any help would be awsome....
Has anyone been able to get this code to work? I am trying to do a very similar process with CCTV data and I want to display an image from a link. When I test it I receive the following error: Please fix the errors in the code and rebuild the project Exception has been thrown by target of an invocation
The only thing I can figure is the PictureProperty may not be the correct control name.
Here is my code.
public void Detail1_Format()
{
string pin_value = Convert.ToString( rpt.Fields["ImagePath"].Value);
string pictureUrl ="http://coagispsom1/cctv" + pin_value;
//Setting up the image to retrieve webrequest
System.Drawing.Image pinImage = null;
System.Net.WebRequest req = System.Net.WebRequest.Create( pictureUrl );
using( System.Net.WebResponse response = req.GetResponse() )
using( System.IO.Stream stream = response.GetResponseStream() )
{
pinImage = System.Drawing.Image.FromStream( stream );
}
//PictureProperty is the name of the Picture control - your's might be a different name
Picture PictureProperty = rpt.Sections["detail"].Controls["PictureProperty"] as Picture;
PictureProperty.HyperLink = pictureUrl;
PictureProperty.DataField = pictureUrl;
PictureProperty.Image = pinImage;}
0 -
Hi,
This code works for my report.
public void Detail1_Format()
{
string URL = Convert.ToString( rpt.Fields["Url"].Value);
//Setting up the image to retrieve webrequest
System.Drawing.Image pinImage = null;
System.Net.WebRequest req = System.Net.WebRequest.Create( URL);
using( System.Net.WebResponse response = req.GetResponse() )
using( System.IO.Stream stream = response.GetResponseStream() )
{
pinImage = System.Drawing.Image.FromStream( stream );
}
//PictureProperty is the name of the Picture control - your's might be a different namePicture PictureProperty = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;
PictureProperty.HyperLink = URL;
PictureProperty.DataField = URL;
PictureProperty.Image = pinImage;
}Marc
0 -
You will sometimes get the error:
Please fix the errors in the code and rebuild the project Exception has been thrown by target of an invocation
in a Report Designer project with no actual errors. The workaround for this is to wrap your code-behind script in a try... catch construction to catch the erroneous error. Although this is not very elegant, it will work.
0 -
I see there is a script to run to provide the image to a "picture object" in the report designer.
here is the code from the previous discussion in this thread:
public void Detail1_Format()
{
string URL = Convert.ToString( rpt.Fields["Url"].Value);
//Setting up the image to retrieve webrequest
System.Drawing.Image pinImage = null;
System.Net.WebRequest req = System.Net.WebRequest.Create( URL);
using( System.Net.WebResponse response = req.GetResponse() )
using( System.IO.Stream stream = response.GetResponseStream() )
{
pinImage = System.Drawing.Image.FromStream( stream );
}
//PictureProperty is the name of the Picture control - your's might be a different namePicture PictureProperty = rpt.Sections["Detail1"].Controls["Picture1"] as Picture;
PictureProperty.HyperLink = URL;
PictureProperty.DataField = URL;
PictureProperty.Image = pinImage;
}What I want to do is to read an image stored on disc with a certain name an place that as the picture, instead of a web request. I see the script tab in the report designer, so do I insert the script code for detail1 picture1? (for example, before print?
Can someone provide the syntax to read a file instead of a web stream? I believe I can then use this method to convert and append the needed jpg plat images into .pdf format for the users.
Jeff
0 -
Hi Jeff,
You don't need a script to do this. If you are using a Picture control, and try to edit the Image property, you will be able to open a file browser and select the image you would like to display. See the sample Parcel.rpx report, which has the image if the house in a Picture control.
-Victoria
0 -
Victoria--
What you say is true, but I want to change the image dynamically from a workflow. So I was going to take the township and range values derived from a query task, and build the image name by substituting values to build the path string to access the images on disc and then place them in the picture control that way. I thought that a script in the report designer may allow me to do that.
Can you recommend a better or easier way to dynamically convert jpg to pdf format in a workflow. I could not see a way using the system.drawing.image functions, so I thought using the report designer may be a way to accomplish this task easily??? I could also assemble mutiple jpg images into a .pdf package.
I will appreciate you input and suggestions.
Jeff
0 -
Sonia--
Can you post your .rpx file you refer to in the thread. I sort of have it working, but I would like to see the settings in the report designer and how you put those variables in. Also I want to be able to use the jpg image name as a argument to the report.
It would be a big favor.
Jeff
0 -
this is an old post but thank you for the code. Was able to get this working through a sub report of a SQL table that had a full url in the table. Thanks! 0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
9 Kommentare