Starting application via Windows Search gives different result for Path.GetFullPath(...)

91 Views Asked by At

I have some strange issue with using Path.GetFullPath method in C#.

On startup of my application it searches for some folders and retrieving the paths via the GetFullPath method. Everything works fine if I start the application via IDE or via double click in the output folder.

(e.g. result for the path -> D:\ExampleApp\Release\Config)

But if i move with the explorer to the output directory and search for the executable via "*.exe" and start my application, the GetFullPath method is returning a string starting on the C directory.

(e.g. result for the path -> C:\ExampleApp\Release\Config)

Is this issue because of the windows search resetting the current directory to C ?

What is the best way to find the starting directory, e.g. Assembly.GetExecutingAssembly().Location ?

1

There are 1 best solutions below

0
On

This may help you... Basically this line gets you to bin/debug folder and you can modify that path to where ever you want. Like I have modified it to get to the Resources folder of my application.

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\Resources\\yourFileInResources";