Arup
Arup

Reputation: 55

How to get the full path of a directory

I have create a directory name 'DbInventory' in E drive of my machine Now in my c# application I want to get the full path of this directoty(DbInventory).

bellow I am mentioning the code I have used

DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;

But this currentDirectoryName string return the file location in C drive.

Upvotes: 1

Views: 4672

Answers (4)

Soner Gönül
Soner Gönül

Reputation: 98848

First of all, DirectoryInfo constructor takes parameter as a string with full path. When you just write a folder name, it gets the location of your Visual Studio's default path which is most common in your C:/ drive and under Bin/Debug folder.

So in my computer, your currentDirectoryName will be;

C:\Users\N53458\Documents\Visual Studio 2008\Projects\1\1\bin\Debug\DbInventory

If you want to get full path name, you can use Path.GetDirectoryName method;

Returns the directory information for the specified path string.

Upvotes: 2

Adil
Adil

Reputation: 148160

You can use Path.GetDirectoryName

DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
string directoryPath = Path.GetDirectoryName(path);

Upvotes: 1

Tintenfiisch
Tintenfiisch

Reputation: 360

You are creating with the

new DirectoryInfo("DbInventory");

a new directory on the default drive (C). Take a look at: MSDN

If you want to get the directory info object of the already created one on drive E you have to specify the path.

Upvotes: 1

Ghost Answer
Ghost Answer

Reputation: 1498

try server.mappath

string currentDirectoryName =Server.MapPath(info.FullName);

hope this will work for you

Upvotes: 0

Related Questions