如何从给定路径获取子文件夹名称Server.MapPath

问题描述:

我想从ASP.NET MVC 3应用程序中的server.MapPath获取文件夹名称。 在此操作中,如果.jpg文件位于该文件夹中,则必须检查(如果给定文件夹名称中存在更多文件夹),并且如果是,则返回该文件夹。如何从给定路径获取子文件夹名称Server.MapPath

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); 
} 
+0

你好谢谢你给了我回应试图获得文件夹,但我没有得到的解决方案,我已经发布我的代码在我的查询请检查一次..并给任何暗示请 – Victor

我不知道我有正确理解qestion,但我认为你要像

string path = Server.MapPath(YOURPATH); 
List<string> files = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories); 

或类似

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) 
} 
+0

您好我正在尝试你的代码,但它显示错误,如“找不到部分o f路径'D:\ victor \ Pivot \ Ilifelooks \ Ilifelooks \ Ilifelooks \ Gallery \ Content \'。 “ – Victor

+0

是否存在路径'D:\ victor \ Pivot \ Ilifelooks \ Ilifelooks \ Ilifelooks \ Gallery \ Content \' – ChrFin

+0

是的它存在于我的服务器路径中该文件夹中还存在一些图像 – Victor