SSRS: Report loads external images, image not found, I can hide image management

My SSRS report downloads logo images for each client from a folder with a specific client number on the report server.

I am writing an expression to form my URL for the image based on the customer number.

..."http://localhost/images/" + iCustomerNumber.ToString() + "/logo.gif" 

I can get this working, but the problem I am facing is that when a particular client has no image, then my report shows a red X instead of a logo. In this case, I expect to hide the image control itself. Any thoughts ????

Another dirty solution would be to ensure that each folder with a particular client has an assigned image! even if there is no logo for the client, I would put blank.gif or spacer.gif, possibly a square pixel in dimension !.

+4
source share
1 answer

You can try adding some code and use it in the Image.Value property to load the default image if the image is not found:

 Public Function GetImage(ByRef CustomerNumber As String) As String ' Customer image Dim ImageCustomerURL As String ImageCustomerURL = "http://localhost/images/" + CustomerNumber + "/logo.gif" ' Default Image if customer image does not exist Dim ImageDefaultURL As String ImageDefaultURL = "http://localhost/images/default.gif" ' Create a web request to see if customer image exists Dim m_Req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ImageCustomerURL) Try Dim HttpWResp As System.Net.HttpWebResponse = CType(m_Req.GetResponse(), System.Net.HttpWebResponse) If HttpWResp.StatusCode = System.Net.HttpStatusCode.OK Return ImageCustomerURL Else Return ImageDefaultURL End If Catch ex As System.Net.WebException If ex.Status = System.Net.WebExceptionStatus.ProtocolError Then Return ImageDefaultURL End If End Try Return ImageDefaultURL End Function 

Then your Image.Value property expression:

 =Code.GetImage(iCustomerNumber.ToString()) 

Edit: set the Visibility.Hidden property instead of using the default image

Well, I thought it would be better to have a default image rather than empty space, but this is really the same idea:

 Public Function HideImage(ByRef CustomerNumber As String) As Boolean ' Customer image Dim ImageCustomerURL As String ImageCustomerURL = "http://localhost/images/" + CustomerNumber + "/logo.gif" ' Create a web request to see if customer image exists Dim m_Req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(ImageCustomerURL) Try Dim HttpWResp As System.Net.HttpWebResponse = CType(m_Req.GetResponse(), System.Net.HttpWebResponse) If HttpWResp.StatusCode = System.Net.HttpStatusCode.OK Return False Else Return True End If Catch ex As System.Net.WebException If ex.Status = System.Net.WebExceptionStatus.ProtocolError Then Return True End If End Try Return True End Function 

Then your Visibility.Hidden property expression:

 =Code.HideImage(iCustomerNumber.ToString()) 
+5
source

Source: https://habr.com/ru/post/1307627/


All Articles