我正在使用Telerik报表工具创建报表并在其上显示一些图像。我使用来自客户端的URL在图片框中显示图像,但是存在给定URL无效的实例,因此它将在报告中显示错误消息。我想只在图像不可用时隐藏图片框,这样错误就不会出现在报告中。我该怎么做?提前谢谢:)
答案 0 :(得分:1)
在您的网站上进行网络搜索。 例如:
Public Sub Run()
Dim myReportImage As Image = GetControl("ReportImage")
myReportImage.Visible = CheckWebImage()
' or
myReportImage.Enabled = CheckWebImage()
End Sub
Private Function CheckWebImage() As Boolean
Dim url As New System.Uri("http://www.url.com/yourImage.jpg")
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
Dim response As System.Net.WebResponse
Try
response = req.GetResponse()
response.Close()
request = Nothing
Msgbox("Website Found!")
Return True
Catch ex As Exception
request = Nothing
Msgbox("Website not found. Check the url and internet connection")
Return False
End Try
End Sub