My project has a folder structure:
- Project,
- Project / Data
- Project / Engine
- Project / Server
- project / front end
On the server (running in the Project / Server folder), I refer to the folder as follows:
var rootFolder = Directory.GetCurrentDirectory(); rootFolder = rootFolder.Substring(0, rootFolder.IndexOf(@"\Project\", StringComparison.Ordinal) + @"\Project\".Length); PathToData = Path.GetFullPath(Path.Combine(rootFolder, "Data")); var Parser = Parser(); var d = new FileStream(Path.Combine(PathToData, $"{dataFileName}.txt"), FileMode.Open); var fs = new StreamReader(d, Encoding.UTF8);
On my Windows computer, this code works fine, because Directory.GetCurrentDirectory() added to the current folder and does
rootFolder.Substring(0, rootFolder.IndexOf(@"\Project\", StringComparison.Ordinal) + @"\Project\".Length);
gets the project root folder (not bin or debug folders). But when I ran it on mac, it got " Directory.GetCurrentDirectory() " sent me to / usr // [something else]. This does not apply to the folder where my project is located.
What is the correct way to find relative paths in my project? Where should I store the data folder so that it is easily accessible for all subprojects in the solution - in particular, for the kestrel server project? I prefer not to store it in the wwwroot folder, because the data folder is maintained by another member on the team, and I just want to access the latest version. What are my options?
source share