C
C#2y ago
gumbarros

Path.Combine to folder behind

Why this is not working?
var root = Path.Combine("/../","/../", builder.Environment.ContentRootPath);
var sharedSettings = Path.Combine(root, "appsettings.json");
var root = Path.Combine("/../","/../", builder.Environment.ContentRootPath);
var sharedSettings = Path.Combine(root, "appsettings.json");
8 Replies
gumbarros
gumbarros2y ago
Output:
gumbarros
gumbarros2y ago
gumbarros
gumbarros2y ago
Expected output: /home/gumbarros/Projects/jjmasterdata/appsettings.json
ero
ero2y ago
"/../" can't be a valid starting path You probably want Path.Join(builder.Environment.ContentRootPath, "..", "..");
canton7
canton72y ago
Path.Combine does weird stuff when one of the parts starts with / as well, that's why we now have Path.Join. But use ".." either way, as @Ero did
HimmDawg
HimmDawg2y ago
Path.Join is .NET7 tho iirc
ero
ero2y ago
gumbarros
gumbarros2y ago
Solved, thanks