[英]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). 我在我的机器的E驱动器中创建了一个目录名'DbInventory'现在在我的c#应用程序中我想获得这个直接的完整路径(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. 但是这个currentDirectoryName字符串返回C盘中的文件位置。
First of all, DirectoryInfo
constructor takes parameter as a string with full path . 首先,
DirectoryInfo
构造函数将参数作为具有完整路径的字符串。 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. 当您只编写文件夹名称时,它会获取Visual Studio默认路径的位置,这在
C:/
驱动器和Bin/Debug
文件夹下最常见。
So in my computer, your currentDirectoryName
will be; 所以在我的电脑中,你的
currentDirectoryName
将是;
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; 如果要获取完整路径名,可以使用
Path.GetDirectoryName
方法;
Returns the directory information for the specified path string.
返回指定路径字符串的目录信息。
You can use Path.GetDirectoryName 您可以使用Path.GetDirectoryName
DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
string directoryPath = Path.GetDirectoryName(path);
try server.mappath 尝试server.mappath
string currentDirectoryName =Server.MapPath(info.FullName);
hope this will work for you 希望这对你有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.