Getting Images From Media Libraries

Naresh Ede asked on September 1, 2017 14:39

Hi

I created a media library , under that i have different folders. In each folder i have different images. Now I want to fetch all the images under a specified folder path.

How can i achieve this.

input is Media library folder path

output is Images in the specified input path

Recent Answers


Chetan Sharma answered on September 1, 2017 15:49

Reference - https://docs.kentico.com/api9/content-management/media-libraries

Modified the reference code.

// Gets the media library
MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo("NewLibrary", SiteContext.CurrentSiteName);

if (library != null)
{
    // Gets all .png files from the "NewFolder" folder of the specified media library
    var mediaFiles = MediaFileInfoProvider.GetMediaFiles()
                     .WhereEquals("FileLibraryID", library.LibraryID)
                     .WhereStartsWith("FilePath", "NewFolder");

    // Loops through individual media library files
    foreach (MediaFileInfo mediaFile in mediaFiles)
    {
        // Your logic
    }
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.