简体   繁体   English

SSRS:报告加载外部图像,未找到图像,我可以隐藏图像控件

[英]SSRS: Report loading external images, image not found, can I hide the image control

My SSRS report loads logo images for each customer from a customer number specific folder on the report server. 我的SSRS报告从报表服务器上的客户编号特定文件夹中加载每个客户的徽标图像。

I write an expression, to form my URL to the image based on th customer number. 我写了一个表达式,根据客户编号形成我的图像URL。

..."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. 我能够使这个工作,但我面临的问题是,当一个特定的客户没有图像时,我的报告显示一个红色的X标记代替徽标。 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!. 即使客户没有徽标,我也会在尺寸上放置一个可能是正方形像素的blank.gif或spacer.gif!

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: 您可以尝试添加一些自定义代码,并在Image.Value属性中使用它来加载默认图像,如果没有找到图像:

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: 然后你的Image.Value属性表达式是:

=Code.GetImage(iCustomerNumber.ToString())

Edit: Set the Visibility.Hidden property rather than use a default image 编辑:设置Visibility.Hidden属性而不是使用默认图像

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: 然后您的Visibility.Hidden属性表达式为:

=Code.HideImage(iCustomerNumber.ToString())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM