views:

294

answers:

1

My SSRS report loads logo images for each customer from a customer number specific folder on the report server.

I write an expression, to form my URL to the image based on th customer number.

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

I am able to get this working, but the problem I face is, when a particular customer doesn't has an image, then my report shows a red X mark in place of the logo. In this case, I expect to hide the image control itself. Any thoughts????

The other dirty solution will be to ensure that each customer specific folder has the designated image! even if there is no logo for a customer, I'll place a blank.gif or a spacer.gif of probably a square pixel in dimension!.

+1  A: 

You could try adding some custom code and use this in the Image.Value property to load a default image if no image is 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 is:

=Code.GetImage(iCustomerNumber.ToString())

Edit: Set the Visibility.Hidden property rather than use a default image

Well, I thought it might be nicer to have a default image rather than a blank space but it's 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 is:

=Code.HideImage(iCustomerNumber.ToString())
Chris Latta
I was looking to hide the control!!!I can fall back to the dirty solution as I mentioned, if visibility cannot be tweaked. I could have a default image in the root folder itself. Rather being duplicated in each sub-folder, in-line with your solution of "ImageDefaultURL" stuff, to be more precise!
System.ArgumentException
Of course visibility can be tweaked - hiding the control is really the same idea. The first solution having a default image in one place means you don't have to replicate the image in every customer folder as per your dirty solution - it just exists in one place, but if there is a customer image then that gets displayed instead.
Chris Latta