Search code examples
c#pathdirectorysubdirectory

How do I get the path/address of a folder within the program solution? (C#)


I'm trying to get the path for a folder called "Template", which I've created in my project solution. My program is called CalculationScheduler.

I have tried:

AppDomain.CurrentDomain.BaseDirectory 

but this gives me the following path:

C:\Users\username\source\repos\AppName\AppName\bin\Debug\

what I want is:

C:\Users\username\source\repos\AppName\AppName\Template

I've also tried:

Path.Combine(baseDirectory, @"..\..\Template");

I thought that by going back two folders using ..\ ..\ it would work, but it doesn't appear to be. Bare in mind that this program must also work if installed on another computer.


Solution

  • You can try something like below probably

    Path.Combine(Directory.GetParent(Directory.GetParent(Directory.GetParent(Environment.CurrentDirectory).FullName).FullName).FullName, "Template")