I don't know why you need your project path, usually what people ned is the path to the directory where currently executing .exe file is. You do it like this:
-
string dirname = Directory.GetCurrentDirectory();
Then, I suppose to get your project directory, you'll need to call Directory.GetParent() a few times (depending on your project's file structure).
Other ways to find your exe directory are:
- string appPath = Path.GetDirectoryName(Application.ExecutablePath);
-
for Form applications and
- string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MyClass)).CodeBase);
for loaded assemblies (.exe, .dll).
You'll need to add certain references to your project to use those, like:
- using System.IO;
-
using System.Reflection;//in the lase example