Joe Joe Joe
Joe Joe Joe

Reputation: 79

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.

Upvotes: 0

Views: 74

Answers (2)

Rahul
Rahul

Reputation: 77846

You can try something like below probably

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

Upvotes: 1

mahlatse
mahlatse

Reputation: 1307

The best way to do this would probably to use a Post Build Events in visual studio, a simple statemet like the one below should allow you to copy your ofolder to the output directory

XCOPY "$(SolutionDir)\Template" "$(TargetDir)\Template\" /S /Y

Upvotes: 0

Related Questions