我的项目中有一个名为“Images”的文件夹。我想获取Image文件夹的路径,以便我可以浏览并获取文件。获取文件夹相对路径的方法
我使用下面的一段代码来满足我上面的要求,它工作正常。
string basePath = AppDomain.CurrentDomain.BaseDirectory;
basePath = basePath.Replace("bin", "#");
string[] str = basePath.Split('#');
basePath = str[0];
string path = string.Format(@"{0}{1}", basePath, "Images");
string[] fileEntries = Directory.GetFiles(path);
foreach (string fileName in fileEntries)
listBox.Items.Add(fileName);
只是想知道像有没有这样做的优雅方式?获取文件夹路径的最佳方式是什么?
这是无关的WPF – 2012-02-01 07:51:35
您可以使用['Directory.GetParent'](http://msdn.microsoft.com/en-us/library/system.io .directory.getparent.aspx)来检索给定目录的父目录 – 2012-02-01 08:11:19