Reputation: 13206
How do you set the URI for an image source to the root directory (i.e. same folder as your exe) in a WPF application?
var myImage = new Image();
myImage.Source = new BitmapImage(new Uri("pack://application:,,,/AssemblyName;component/speedline.png", UriKind.Absolute));
I've tried the above and keep getting the following error message:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll. Additional information: Could not load file or assembly 'AssemblyName, Culture=neutral' or one of its dependencies. The system cannot find the file specified.
I am obviously doing something very wrong, but can guarantee that the png file can be found at C:\Users\Admin\Documents\Visual Studio 2013\Projects\Speedy\Speedy\bin\Debug
, in the same folder as my exe file, but how do I reference it?
Upvotes: 1
Views: 2599
Reputation: 1279
Create a new folder under the solution explorer called component and add the existing image under that. Now try using the Relative path.
myImage = new BitmapImage(new Uri("/component/speedline.png", UriKind.Relative));
Upvotes: 5