Umbraco:有没有办法获取媒体(物理文件夹)下的文件夹列表

Umbraco: Is there a way to get the list of folder under the Media (Physical Folder)

我只是想在媒体文件夹(物理文件夹)下创建一个文件夹列表(仅文本值)。

媒体文件夹位于根文件夹。(见图)

我尝试了下面的代码来测试我是否可以得到最后一个文件夹:

var contentService = Services.ContentService;
var folderList = contentService.GetRootContent().Last();
IContent s = folderList;

string nameOfLastFolder = folderList.Name.ToString();

但是它回家了

我也试过下面的代码:

var mediaService = Services.MediaService;
var folderList = mediaService.GetRootMedia().Last();
IMedia s = folderList;

string nameOfLastFolder = folderList.Name.ToString();

但是它返回了最后一个媒体文件的名称,如果我要获取的是后台的媒体而不是物理文件,那么它是正确的。 (见下图)

我想得到的是物理上的媒体文件夹列表,而不是在后台查看媒体。我想创建物理媒体文件夹列表:

我希望你能帮我解决这个问题。谢谢。

您应该遍历文件系统中的文件夹,而不是使用 Umbraco 服务(列出数据库条目)。

示例

string pathToFiles = HostingEnvironment.MapPath("/Media");
string[] fileList = Directory.GetFiles(pathToFiles);