How to set relative path to Images directory inside C# project?

c#, relative-path

Solution

If you are using LinkedResource() in C# it is most likely not to pickup your relative URI or the file location.

You can use some extra piece of code

var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var logoimage = Path.Combine(outPutDirectory, "Images\\logo.png");
string relLogo = new Uri(logoimage).LocalPath;
var logoImage = new LinkedResource(relLogo)

Now it will pickup your relative path, convert this to absolute path in memory and it will help you get the images.

Problem

I am working on C# project i need to get the images from Images directory using relative path. I have tried ``` var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\Images\logo.png"; var logoImage = new LinkedResource(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)+@"\Images\logo.png") ``` But no luck with these... I have made the images to be copied to output directory when the program is running but it doesn't pickup those images.

Original source