How to get image from relative URL in C#, the image cannot be in the project

Posted by red-X on Stack Overflow See other posts from Stack Overflow or by red-X
Published on 2010-04-26T11:32:52Z Indexed on 2010/04/26 11:33 UTC
Read the original article Hit count: 224

Filed under:
|
|
|

I have a project where I'm loading relative image Uri's from an xml file. I'm loading the image like this:

if (child.Name == "photo" &&
    child.Attributes["href"] != null &&
    File.Exists(child.Attributes["href"].Value))
{
    Image image = new Image();
    image.Source = new BitmapImage(new Uri(child.Attributes["href"].Value, UriKind.RelativeOrAbsolute));
    images.Add(image);
}

Where the "child" object is an XmlNode which could looks like this

<photo name="info" href="Resources\Content\test.png"/>

During debug it seemd images is filled with actual images but when I want to see them in any way it shows nothing. Weird thing is when I include the images in my project it does work, I however dont want to do that since my point for using an xml file is so that it would be lost since you'd have to rebuild the program anyway after a change.

© Stack Overflow or respective owner

Related posts about c#

Related posts about url