Manudog Manudog - 1 year ago 102
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

Answer Source

Try this:

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


In the image Properties window set Build Action to Resource.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download