Delete Media Folder
# help-with-umbraco
c
I have a function that deletes media in a particular media folder. It works fine. But I also want to delete the folder. I don't see anything in IMediaService that does that. Any suggestions?
h
You probably need the fileservice for that
or do you mean the folder in the backoffice?
c
Really? They're only notional folders though aren't they?
The folder in the Media section in the back office.
I sincerely hope media.delete() isn't leaving the physical folders hanging around on disk, lol
h
Folders are IPublishedContent Items maybe
c
Hmmm. Not sure. It's very IMedia-ish though. I know I create them with this: var newMediaFolder = _mediaService.CreateMedia(parentFolderName, insertFolderID, "Folder");
I have a vague memory of asking this in V8 a few years ago, but can't remember the answer, lol
h
something like this should work
Copy code
csharp
        var _mediaFolder = Umbraco.MediaAtRoot().DescendantsOrSelf<Folder>().First(f => f.Name == title);
        var folder = _MediaService.GetById(_mediaFolder.Id);
        _MediaService.Delete(folder);
c
So you mean just treat a folder like a media item? Cool, I'll give it a go.
It worked, thanks 🙂
s
It is, indeed, a media type
11 Views