I have a Visual Studio solution with the following structure:
- root - src - project01 - project02 - config - application.config - database.dacpac Now, assuming I am executing a code from the path:
C:\DEV\root\project01\bin\release\project01.exe How can I find the first occurrence of the file "application.config" for example?
I know that I can start with this:
public string GetExecutingDirectory(){ { string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path); } And use it in the following way:
var executingDirectory = GetExecutingDirectory(); But now, how can I traverse the Root Tree back and forward until I find the file I am looking for? I tried this code but it doesn't find anything:
var path = Directory .GetFiles(executingDirectory, "**/application.config", System.IO.SearchOption.AllDirectories); I need it because I am running Integration Tests from different paths and they need these files which can be in a different location of the solution tree depending on the DEV machine configuration so I need to use the "pattern" because the structure can be different from PC to PC.