C
C#2y ago
SWEETPONY

❔ how to get path to folder?

I'd like to create folder in another csproj, how can I do it? Now I only can do this using full path:
var folder = "C:\\Users\\Desktop\\dotnet\\Tools.ReportDesigner\\DebugReportData";
using var sw = File.CreateText( $"{folder}\\report.txt" );
var folder = "C:\\Users\\Desktop\\dotnet\\Tools.ReportDesigner\\DebugReportData";
using var sw = File.CreateText( $"{folder}\\report.txt" );
where Tools.ReportDesigner is another csproj in sln
9 Replies
TravestyOfCode
For folders you use one of the Directory.CreateDirectory methods: https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory?view=net-7.0
Directory.CreateDirectory Method (System.IO)
Creates all the directories in a specified path.
SWEETPONY
SWEETPONYOP2y ago
I need a path where folder will be created thats why I asked “how to get path”
TravestyOfCode
Directory.GetDirectories Method (System.IO)
Returns the names of subdirectories that meet specified criteria.
SWEETPONY
SWEETPONYOP2y ago
I need to pass a path to this method and I dont have it I’d like to get path for folder in another csproj
TravestyOfCode
So how do you determine which csproj to search for?
SWEETPONY
SWEETPONYOP2y ago
sln first project second project im in first and wanna create folder in second
TravestyOfCode
So typically solutions are stored under the "C:" drive, so you can start your directory search there. Then use the searchPattern part of GetDirectories to filter what directory you are looking for. You could also start with Directory.GetCurrentDirectory() and then use Directory.GetParentDirectory() to navigate up from where your app is, searching the directory for the other project name. If you don't find it, get the next parent until there's no more parents.
TripleTom
TripleTom2y ago
Path.GetDirectoryName()?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server