Solved

Get directory path

Posted on 2010-09-14
5
540 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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