I want get the folder names from server.MapPath
in ASP.NET MVC 3 application.
In this action, I have to check (if ther开发者_StackOverflow中文版e exist more folders in a given folder name) if a .jpg file is in that folder and if so, return that folder.
string path = Server.MapPath("Content/");
DirectoryInfo dInfo = new DirectoryInfo(path);
DirectoryInfo[] subdirs = dInfo.GetDirectories();
if (Directory.Exists(path))
{
ArrayList ar = new ArrayList();
// This path is a directory
ar.Add(path);
//ProcessDirectory(path);
}
I'm not sure I've understand the qestion correctly, but I think you want something like
string path = Server.MapPath(YOURPATH);
List<string> files = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
or something like
string path = Server.MapPath(YOURPATH);
List<string> picFolders = new List<string>();
if(Directory.GetFiles(path, "*.jpg").Length > 0)
picFolders.Add(path)
foreach(string dir in Directory.GetDirectories(path, "*", SearchOption.AllDirectories))
{
if(Directory.GetFiles(dir, "*.jpg").Length > 0)
picFolders.Add(dir)
}
精彩评论