Add pictures to PictureBox dynamically

3 posts, 0 answers
  1. Richard
    Richard avatar
    2 posts
    Member since:
    Oct 2016

    Posted 20 Oct 2016 Link to this post


    I'm new to Teleric and am struggling to dynamically load a picture into a PictureBox. No matter what I try I get "Could not find part of the path". I found this function in an article on User Functions but it doesn't work: I get the same error message and "Invalid URL: the url is empty":


        Private Sub PictureBoxRecipePicture_ItemDataBinding(sender As Object, e As EventArgs) Handles PictureBox1.ItemDataBinding
                Me.PictureBox1.Value = ResolveUrl("C:\MyPictures\MyPicture.jpg")
            Catch ex As Exception
            End Try
        End Sub

        Public Shared Function ResolveUrl(relativeUrl As String) As System.Drawing.Image
            Dim path As String = System.Web.HttpContext.Current.Server.MapPath(relativeUrl)
            Return System.Drawing.Image.FromFile(path)
        End Function


    Can anyone point me in the right direction for how to do this? I realise there may be a much better way of dynamically assigning pictures but simply can't find a method that works.

    Thanks for reading

  2. Richard
    Richard avatar
    2 posts
    Member since:
    Oct 2016

    Posted 20 Oct 2016 in reply to Richard Link to this post

    Incidentally, I also tried this from the PictureBox example and it didn't work either. I think the original example i posted expects a relative path but surely this should work?:

            Dim image1 As Image = Image.FromFile("C:\MyPictures\MyPicture.jpg")
            Me.PictureBox1.Value = image1
  3. Stef
    Stef avatar
    3610 posts

    Posted 24 Oct 2016 Link to this post

    Hello Richard,

    If the image will be changed dynamically, our recommendation is to use a user function that returns an Image object, path to an image file on the server or the image bytes - PictureBox: Data Binding.

    If there is an error on preview, it is related to the attempt to get the image. If it is about the path to the image, please check if the image is on the server machine at the specified address.

    In order to provide you more accurate suggestions, please post the error message and the PictureBox settings (code snippet), including details in which preview you get the error (design-time or in a viewer).

    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top