locked
External image in report rdlc RRS feed

  • Question

  • User-1305530094 posted

    Hi,

    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

    Friday, September 11, 2015 1:56 AM

Answers

  • User-1305530094 posted

    Dear All,

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

    1. 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
    1. To show the image on webform I decode the URI to URL 
    2. 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

    3. 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!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 12, 2015 4:39 AM

All replies

  • User1724605321 posted

    Hi  Embryologist ,

    You could dynamically config the path of the external image using Report parameter:

            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
            ReportViewer1.LocalReport.EnableExternalImages = true;
            string imagePath = new Uri(Server.MapPath("~/images/Mudassar.jpg")).AbsoluteUri;
            ReportParameter parameter = new ReportParameter("ImagePath", imagePath);
            ReportViewer1.LocalReport.SetParameters(parameter);
            ReportViewer1.LocalReport.Refresh();

    You could refer to link below for an entire demo about how to dynamically add and display external Image in RDLC Report:

    http://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx .

    Best Regards ,

    Nan Yu

    Friday, September 11, 2015 3:36 AM
  • User-1305530094 posted

    Thanks for your reply,

    Actually I am aware of this example. Still is there a way to fetch the URL from existing field in the report?

    Friday, September 11, 2015 4:03 AM
  • User-1305530094 posted

    Dear All,

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

    1. 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
    1. To show the image on webform I decode the URI to URL 
    2. 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

    3. 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!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 12, 2015 4:39 AM