0

I upload images to server and store their path in a table (varchar(MAX)).

I managed to create a report and show the records from that table but I could not bind the image to its datasource (stored path).

My path looks like this:

~/ARTSQLDATA/PTDIR/15090248/IDFTO/15090248PPID.jpg

I am using the following code to populate my dataset

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        RepVuerCtl.ProcessingMode = ProcessingMode.Local
        RepVuerCtl.LocalReport.ReportPath = Server.MapPath("~/Account/RepPtProf.rdlc")
        RepVuerCtl.LocalReport.EnableExternalImages = True
        Dim DsPtProf As DSPtProf = GetData()
        Dim datasource As New ReportDataSource("PatientProfile", DsPtProf.Tables(0))
        RepVuerCtl.LocalReport.DataSources.Clear()
        RepVuerCtl.LocalReport.DataSources.Add(datasource)
    End If
End Sub
Private Function GetData() As DSPtProf
    Dim ARTSQLCON As SqlConnection = New SqlConnection(-------())
    Dim SQLCmd As New SqlCommand()
    SQLCmd.Connection = ARTSQLCON
    Using DtaRdr As New SqlDataAdapter(SQLCmd)
        SQLCmd.CommandType = CommandType.StoredProcedure
        SQLCmd.CommandText = "RepTblRegPtProf"
        SQLCmd.Parameters.Add("@FileNum", SqlDbType.Int).Value = 15090248 
        Using DsPtProf As New DSPtProf()
            DtaRdr.Fill(DsPtProf, "RepTblRegPtProf")
            Return DsPtProf
        End Using
    End Using

End Function

Please Help Thanks!

JSON
  • 1,583
  • 4
  • 31
  • 63

1 Answers1

0

I found a solution that I want to share with you and I would love to hear your feedback,

I modified my uploader function to save the image path in URI format(Encoded) (ie..

Dim ImgURI As String = New Uri(Server.MapPath("URL String")).AbsoluteUri    

To show the image on webform I decode the URI to URL

Function ConvertURI(URI As String)
    Dim DecodeURI As String = HttpUtility.UrlDecode(URI) 'Decode URI string
    Dim SubURI = DecodeURI.Substring(DecodeURI.IndexOf("Your Folder"))
    Dim URL As String = "~/" & SubURI ' Restore the URL string format
    Return URL
End Function
' then in your code

Dim ImgURL as string = ConvertURI("Your URI")
Sampleimg.ImageUrl = ImgURL

To show the image in your RDLC report just set the image control source to external and assign the image value to field value in your table Your feedback is highly appreciated, Thanks!

JSON
  • 1,583
  • 4
  • 31
  • 63