Search code examples
c#urirelative-pathabsolute-path

Local path URI in C# WPF


If I use an open file dialog box that returns the absolute value of the file this works just fine:

  BMP = new BitmapImage(new Uri(filename));

However, I want to have a text file that contains the names of the files, like this:

01TopographicalMap.bmp
01ElevationCompressed.elv
01Terrain.trn
01Placenames.pns

These files are loaded sequentially. Unfortunately, the previous Uri(filename) call barfs because it wants the whole absolute path. We're already in the same folder. What do I have to do to get the Uri to just default to the folder it's already in?

Thanks, for the help.


Solution

  • You can use Directory.GetCurrentDirectory()

    Or:

    Path.Combine(Directory.GetCurrentDirectory(), filename);