Dynamic Pictures from Url - Report Designer 4.1
Using Report designer 4.1, I'm attempting to load my report based on the feature that has been selected. Trying to use the script
below, but can't seem to get it to work due to "Exception has been thrown by the target of an invocation"
Any help would be greatly appreciated.................Walter
public void detail_Format()
{
string grave_number = Convert.ToString( rpt.Fields["FullGraveNumber"].Value);
string pictureUrl ="https://gisdev2.greatersudbury.ca/cemetery/images/3/=" + grave_number;
//Setting up the image to retrieve webrequest
System.Drawing.Image nicheImage = null;
System.Net.WebRequest req = System.Net.WebRequest.Create( pictureUrl );
using( System.Net.WebResponse response = req.GetResponse() )
using( System.IO.Stream stream = response.GetResponseStream() )
{
nicheImage = System.Drawing.Image.FromStream( stream );
}
Picture NicheWallPic = rpt.Sections["detail"].Controls["NicheWallPic"] as Picture;
NicheWallPic.HyperLink = pictureUrl;
NicheWallPic.DataField = pictureUrl;
NicheWallPic.Image = nicheImage;
}-
Hi Walter,
rpt.Fields["fieldname"] will reference fields created in the Fields section of Report Designer, and doesn't automatically refer to fields attributes of the feature that you are running the report on.
I was able to get this to work with my data by changing how you access the grave number to pull the field value from a textbox in the report, rather than the Fields section in Report Designer. Note that if you don't need this value to actually display in the report itself, you can make the textbox invisible.
public void detail_Format() { //Change these values to match your field names string textboxName = "graveNumberTextBox"; string grave_number = ((TextBox)rpt.Sections["detail"].Controls[textboxName]).Value.ToString(); string pictureUrl = "https://gisdev2.greatersudbury.ca/cemetery/images/3/="+grave_number; //Setting up the image to retrieve webrequest System.Drawing.Image nicheImage = null; System.Net.WebRequest req = System.Net.WebRequest.Create( pictureUrl ); using( System.Net.WebResponse response = req.GetResponse() ) using( System.IO.Stream stream = response.GetResponseStream() ) { nicheImage = System.Drawing.Image.FromStream( stream ); } Picture NicheWallPic = rpt.Sections["detail"].Controls["NicheWallPic"] as Picture; NicheWallPic.HyperLink = pictureUrl; NicheWallPic.DataField = pictureUrl; NicheWallPic.Image = nicheImage; }0 -
Victoria,
I still get an error "Exception has been thrown...." I have a textbox which points to the FullGraveNumber field, but the name of this textboxname to "graveNumberTextBox" which should yield the grave_number dynamically. I just can't see where the problem is in the script. It's exactly the same as the one you provided.
/customer/servlet/servlet.FileDownload?file=00P6000000em1EdEAI
Walter
0 -
Hi Walter,
Try adjusting the 5th line of code from this:string grave_number = ((TextBox)rpt.Sections["detail"].Controls[textboxName]).Value.ToString();
To this:string img = ((TextBox)rpt.Sections["detail"].Controls["img_textbox"]).Text;and see if that solves the issue.
Regards,
?Carmen0 -
I am having a similar situation, can someone help? 0 -
Hi Ben,
Troubleshooting problems with the built-in scripts for Report Designer is very difficult.
Rather than using a script within the RPX to add data to the report, we recommend using a Dataset Tranformer workflow to add new columns to the DataTable that will be used by the report.
This lets us use Workflow Designer to build the workflow, and use Log activities to assist with troubleshooting if things do not work.
If you'd like help creating a Dataset Transformer workflow, please open a support case, and we'll see if we can find a way to do it.
Regards,
-Malcolm0
Please sign in to leave a comment.
Comments
5 comments