I am just trying to create a list (textual value only) of folders under the Media folder (Physical Folder).
Media folder is located at the root folder.(See the image)
I tried the following code just to test if I can get the last folder:
var contentService = Services.ContentService;
var folderList = contentService.GetRootContent().Last();
IContent s = folderList;
string nameOfLastFolder = folderList.Name.ToString();
But it returned Home
I also tried the following code:
var mediaService = Services.MediaService;
var folderList = mediaService.GetRootMedia().Last();
IMedia s = folderList;
string nameOfLastFolder = folderList.Name.ToString();
But it returned the name of the last media file which is correct if what I am trying to get is the media in the backstage but not the physical one. (See the following image)
What I want to get is the list of media folder physically, not in the the backstage view media. I want to create a list of the physical media folder:
I Hope that you can help me with this. Thanks.
You should loop through the folders in the filesystem instead of using the Umbraco service (which lists the database entries).
Example
string pathToFiles = HostingEnvironment.MapPath("/Media");
string[] fileList = Directory.GetFiles(pathToFiles);