I'm having a heck of a time loading an image from the path where the program is being run.

    Dim image As New BitmapImage
    Dim imagePath As String = "keepass.png"
    image.BeginInit()
    image.UriSource = New Uri(imagePath, UriKind.Relative)
    image.EndInit()

    ProductImage.Source = image

I can't seem to use a relative path to my image. If I put an absolute value in there, it shows. I'm in debug mode and have the image in the debug folder. This should work, shouldn't it? I've had this problem in other projects too!

I found a solution, but it doesn't use the relative path.

    Dim image As New BitmapImage
    image.BeginInit()
    image.UriSource = New Uri(Environment.CurrentDirectory & "\" & ProductImageLocation, UriKind.Absolute)
    image.EndInit()
    ProductImage.Source = image

I'm left wondering why the relative path doesn't work as I expect it to?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.