C
C#2y ago
yotabit

Project Path

How can I get the Uri path to my project? What I get: D:\csharp\MyFirstProject\MyFirstProjectUI\bin\Debug\net6.0-windows\ What I want: D:\csharp\MyFirstProject\MyFirstProjectUI\Resources\ What I tried:
AppDomain.CurrentDomain.BaseDirectory.ToString();
Environment.CurrentDirectory;
AppDomain.CurrentDomain.BaseDirectory.ToString();
Environment.CurrentDirectory;
Resources is a folder I created. The root of my project - what I'm trying to get - is D:\csharp\MyFirstProject\MyFirstProjectUI\
5 Replies
yotabit
yotabit2y ago
Got it No. I'm not Thank you for the help!
Servator
Servator2y ago
Environment.CurrentDirectory.Split(@"\")[..^3]
Environment.CurrentDirectory.Split(@"\")[..^3]
Then you can use Path.Combine() but still you can use Resources for this
yotabit
yotabit2y ago
Given what Retax wrote, I found that it's possible to do without the split function
private static string path = GetThisFilePath();
private readonly string directory = Path.GetDirectoryName(path);
private static string path = GetThisFilePath();
private readonly string directory = Path.GetDirectoryName(path);
I'm wondering if there isn't a straightforward solution and if it's indeed a good idea to do like this
jcotton42
jcotton422y ago
@dp what do you need this for?
yotabit
yotabit2y ago
I have a folder called Resources. Inside, I have images and audios. I'd like to open one of them as I need So, I need to find their path. I found a way to get my source code path, then I added /Resources and that's it. Now I can access them Is there a better way to do it? Should I leave these Resources somewhere else?