get project directory in csharp

To get the project directory in C#, you can use the AppDomain.CurrentDomain.BaseDirectory property. This will return the path of the base directory of the current application domain, which should be the project directory.

main.cs
string projectDirectory = AppDomain.CurrentDomain.BaseDirectory;
65 chars
2 lines

You can also use the Directory.GetParent method to get the parent directory of the current directory, which should be the project directory.

main.cs
string projectDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
96 chars
2 lines

Note that the second method assumes that the current working directory is set to the project directory. If this is not the case, you may need to adjust the path accordingly.

gistlibby LogSnag