List media libraries using MediaLibrariesViewer and link the gallery

Chris . asked on January 3, 2018 22:21

Hi there,

for some reason I'm unable to figure out how to do the following:

  • display a subset of existing media libraries, filtered by the library name

  • link the gallery to the library teaser image and description

What I have so far:

  • setting the following filter returns no library at all: WHERE condition: FilePath LIKE N'U21%'

  • I'm using the MediaLibrariesViewer using this transformation:

<div class="MediaListItem">
    <table>
    <tr>
        <td class="MediaLibraryListPhoto">
            <a href='/getmedia/<%# Eval("LibraryGUID") %>/<%# Eval("LibraryName") %>'>
            <%# IfEmpty(Eval("LibraryTeaserPath"), "<img border='0' src=\"~/App_Themes/CommunitySite/Images/DefaultMediaTeaser.gif\" alt=\"\" />", "<img src=\"" + URLHelper.GetAbsoluteUrlWithPort(ValidationHelper.GetString(Eval("LibraryTeaserPath"), "")) + "?width=180\" alt=\""+ Eval("name") +"\" border='0' />") %>
            </a>
        </td>
        <td class="MediaLibraryListDescription">
            <div class="MediaLibraryListDescriptionText">
                <strong>
                <%# Eval("LibraryDescription") %>
                </strong>
            </div>
        </td>
    </tr>
    </table>
    <div class="MediaListItemBottom"></div>
</div>

The link is obviously wrong but I have no idea how to get the gallery url.

I'm grateful for any help.

ps: as you've seen by now I'm no Kentico expert

Recent Answers


Peter Mogilnitski answered on January 5, 2018 16:34 (last edited on January 5, 2018 19:54)

I would suggest to get the default installation of Kentico and take a look how it is done there. If you get Corporate site example and go examples/web parts/media library/media library viewer. You will see the example of the default usage of this web part.

From what I see you would need 2 pages:

  1. Page with media library viewer web part - to list and filter media libraries
  2. Page with media gallery web part - list the content of selected media library.

To simplify the process you can make the gallery page work with query string so in the library viewer transformation you do something like:

<a href="~/Examples/Web-parts/Media-library/Media-gallery-file-list.aspx?LibraryCodeName=<%#Eval("LibraryName")%>">
<%# LimitLength(ResHelper.LocalizeString(Convert.ToString(Eval("LibraryDisplayName", true))), 20, "...") %>
</a>

on the gallery page you make datasource web part take the name of library from query string

Image Text

So Basically I've taken two examples and linked them together:

  • /Examples/Web-parts/Media-library/Media-libraries-viewer.aspx
  • /Examples/Web-parts/Media-library/Media-gallery-file-list.aspx

Hope this will get you started.

P.S. Filtering is done on the media library table, actually two main tables are:

select * from Media_File
select * from Media_library

Where you use media library viewer it works with Media_library which table doesn't have the filePath column, but is has LibraryFolder column, so you use WHERE like: LibraryFolder LIKE N'U21%'

0 votesVote for this answer Mark as a Correct answer

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