What control for selecting file from specific media library?

Tomasz Sikora asked on September 13, 2017 10:27

What control do I need to use to select file from specific media library? For example: I have media library "Authors" and I want to select file only from this library while creating new content-only page. Is there a control I can use for this?

  • Only selecting files from "Authors" library
  • Returning file URL

If there is no out-of-the-box solution, could you give me some hi-level advices what I need to use or what I need to search for?

There is MediaSelection control, but it's not configurable to select only from specific media library.

Correct Answer

Peter Mogilnitski answered on September 13, 2017 12:27

There is no out of the box solution. What you can you do is, for example: is create new form control MediaSelectionCustom. Copy code from MediaSelection form control (/CMSFormControls/Media/MediaSelectionControl.ascx) and play around with DialogConfig Properties to configure pop-up dialog settings (hide tabs, set library etc, set starting path etc.)

/// <summary>
/// Setups selection control.
/// </summary>
private void SetupControl()
{
    // Setup control
    mediaSelector.DialogConfig.LibGlobalLibraryName =
        "Name of the available media library. Set when only one media library should be available.";
    mediaSelector.DialogConfig.HideWeb = true; // indicates if web tab should be hidden
    mediaSelector.DialogConfig.LibStartingPath = "Starting path of media library folder tree";
    ...
2 votesVote for this answer Unmark Correct answer

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