Manudog Manudog - 2 months ago 5x
C# Question

How to change absolute URI to relative?

I wish I could change the path of the source image, to match the folder of my project.

Current code

img1.Source = new BitmapImage(new Uri("C:/Users/User/Documents/Visual Studio 2015/Projects/Referenciel/WpfApplication1/Resources/bateleur.gif"));

What I am trying to set up

img1.Source = new BitmapImage(new Uri(@"\Referenciel\WpfApplication1\Resources\bateleur.gif"));

But I have an error : Invalid URI - Unable to determine the URI format.

Thank you


Try this:

img1.Source = new BitmapImage(new Uri(@"..\Resources\bateleur.gif", UriKind.Relative));


In the image Properties window set Build Action to Resource.