I am using AppDomain.CurrentDomain.BaseDirectory
and I want to go one step backwards but couldn't figure out how? Below is the example,
CODE :
string path = AppDomain.CurrentDomain.BaseDirectory;
RESULT :
"C:\\\\Mainline Code\\\\IxExpress\\\\.NET Applications\\\\IXTextIndexBuilder\\\\IXTextIndexBuilder\\\\bin\\\\Debug\\\\"
EXPECTED RESULT:
"C:\\\\Mainline Code\\\\IxExpress\\\\.NET Applications\\\\IXTextIndexBuilder\\\\IXTextIndexBuilder\\\\bin"
You can use something like the following to get the parent of a given directory:
string dirName = AppDomain.CurrentDomain.BaseDirectory; // Starting Dir
FileInfo fileInfo = new FileInfo(dirName);
DirectoryInfo parentDir = fileInfo.Directory.Parent;
string parentDirName = parentDir.FullName; // Parent of Starting Dir
使用以下代码段:
string path = (new FileInfo(AppDomain.CurrentDomain.BaseDirectory)).Directory.Parent.FullName;
Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.