Try our conversational search powered by Generative AI!

Get Local MediaData


I'm new to EPiServer and I am trying to get all the MediaData from a local folder of a page that is not the root. I have tried to get it with the following code but I get zero back. I am doing something wrong because I have a file in my currentPage? Any ideas?

Feb 27, 2016 22:30

Check out the contentassetshelper class and the GetOrCreateMediaAssetsFolder method.

Then you can list children from that one...the method above will return an assets folder which has a content link property. Use that in your list children method above as root.

Edited, Feb 28, 2016 7:52

I have tried it but I do not get the files under currentPage using GetOrCreateAssetFolder.

            var contentAssetFolder = contentAssetHelper.GetOrCreateAssetFolder(CurrentPage.ContentLink);
Feb 28, 2016 11:24

I have tried getting all children using the abov without getting my file.

Feb 28, 2016 11:25

Have you tried.GetChildren<IContent>(contentAssetsFolder)?

That should give you everything in page files. In your above code you are asking for any children of type content folder, so it won't give you normal images etc.

Edited, Feb 28, 2016 12:10

Thank you :)! Works like a charm!

Feb 28, 2016 17:28

Sweet! Remember to filter them on access rights and publish status since GetChildren doesn't do that by default. :)

I normally use FilterForVisitor in Episerver.Filters namespace...or an extension that looks a little prettier.

Edited, Feb 28, 2016 17:46
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.