Solved

Get directory path

Posted on 2010-09-14
5
537 Views
Last Modified: 2012-05-10
Hello
With
string paht = System.IO.Directory.GetCurrent Directory();
I get the Path: "D:\MyProjects\TestProject\UI\binDebug"

How can I get the Path "D:\MyProjects\TestProject" ? (is two levels higher)
0
Comment
Question by:ICSAutomation
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33671693
If I may ask: why do you need that path, because the first path has the name of the path where the exe resides.
When you deploy the application, it will contain the correct path.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 20 total points
ID: 33671710
you need the "parent directory" (of the parent :))

http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.parent.aspx


DirectoryInfo di = New DirectoryInfo(System.IO.Directory.GetCurrent Directory().ToString());
DirectoryInfo pa = di.Parent.Parent
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 20 total points
ID: 33671736
That path returned is the current directory - you can modify the initial working directory in the project settings if you wished.
Typically the current directory is where the exe file is to be found BUT it can be different under certain circumstances.  If you want to use this to find where your exe is located on disc then it is a dangerous technique
0
 
LVL 5

Assisted Solution

by:Priya Perumpilavil
Priya Perumpilavil earned 20 total points
ID: 33672182
just try this
  private void button1_Click(object sender, EventArgs e)
        {
            string fullpath = System.IO.Directory.GetCurrentDirectory().ToString();

            string Parents = System.IO.Directory.GetParent(fullpath).ToString();
           
            label2.Text = System.IO.Directory.GetParent(Parents).ToString(); ;


        }
0
 
LVL 2

Expert Comment

by:sumeetsuvi
ID: 33672476
Use as it one line code...

first add
using System.IO;
string path = System.IO.Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory().ToString()).ToString()).ToString();
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question