How can i get the current directory of Project folder?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeLouch Fenette
    New Member
    • Aug 2011
    • 16

    How can i get the current directory of Project folder?

    My project name ImageProfiler. My project is in the drive C: then how can i get the path of my project.. the output looks like this "C:\ImageProfil er"
  • arie
    New Member
    • Sep 2011
    • 64

    #2
    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:
    Code:
    string dirname = Directory.GetCurrentDirectory();
    Then, I suppose to get your project directory, you'll need to call Directory.GetPa rent() a few times (depending on your project's file structure).

    Other ways to find your exe directory are:

    Code:
    string appPath = Path.GetDirectoryName(Application.ExecutablePath);
    for Form applications and

    Code:
    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:

    Code:
    using System.IO;
    using System.Reflection;//in the lase example

    Comment

    Working...