Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Get Local MediaData

Vote:
 

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?

contentRepository.GetChildren(CurrentPage.ContentLink).ToList()
#145199
Feb 27, 2016 22:30
Vote:
 

Check out the contentassetshelper class and the GetOrCreateMediaAssetsFolder method.

http://world.episerver.com/documentation/Class-library/?documentId=cms/7.5/82E86AC1

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.

#145200
Edited, Feb 28, 2016 7:52
Vote:
 

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

            var contentAssetFolder = contentAssetHelper.GetOrCreateAssetFolder(CurrentPage.ContentLink);
#145201
Feb 28, 2016 11:24
Vote:
 
contentRepository.GetChildren<ContentFolder>(contentAssetFolder.ContentLink)

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

#145202
Feb 28, 2016 11:25
Vote:
 

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.

#145203
Edited, Feb 28, 2016 12:10
Vote:
 

Thank you :)! Works like a charm!

#145205
Feb 28, 2016 17:28
Vote:
 

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.

#145206
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.