我在我的机器的E驱动器中创建了一个目录名称'DbInventory' 现在在我的c#应用程序中,我想获取此directoty(DbInventory)的完整路径。如何获取目录的完整路径
波纹管我提的代码我用
DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
但这currentDirectoryName字符串在C盘恢复文件的位置。
我在我的机器的E驱动器中创建了一个目录名称'DbInventory' 现在在我的c#应用程序中,我想获取此directoty(DbInventory)的完整路径。如何获取目录的完整路径
波纹管我提的代码我用
DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
但这currentDirectoryName字符串在C盘恢复文件的位置。
首先,DirectoryInfo
构造函数接受参数与完整路径的字符串。当您只写一个文件夹名称时,它会得到您的Visual Studio默认路径的位置,这在您的C:/
驱动器和Bin/Debug
文件夹中最为常见。
所以在我的电脑里,你的currentDirectoryName
会是;
C:\Users\N53458\Documents\Visual Studio 2008\Projects\1\1\bin\Debug\DbInventory
如果你想获得全路径名,您可以使用Path.GetDirectoryName
方法;
返回指定路径字符串的目录信息。
尝试使用Server.Mappath
string currentDirectoryName =Server.MapPath(info.FullName);
希望这会为你工作
DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
string directoryPath = Path.GetDirectoryName(path);
你有没有使用Google? –
为什么您确定应用程序将在E驱动器上查找目录而不是C驱动器上的目录? –
在猜测...... C盘位置是否包含“bin/debug”? – Sayse