Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Guy Pucill 23 posts 73 karma points
    May 11, 2014 @ 01:33
    Guy Pucill
    0

    Whitch Data Type for choosing a Media Folder?

    @inherits umbraco.MacroEngines.DynamicNodeContext
        @{ 
        var  folderId = Model.GetPropertyValue("filfolder");
    
         var  chosenMedia  =  Model.MediaById(@folderId);
    
         if  (chosenMedia.NodeTypeAlias  ==  "Folder")
         {
             foreach  (var  img  in  chosenMedia.Children)
             {
                 if  (img.NodeTypeAlias  ==  "Image")
                 {                   
                     <img  src="@img.umbracoFile"/>
                 }
             }
         } 
    }
    

    The above is used for listing all media, of type "Image", in a folder with ID taken from a document type field. Which data type should be used for chooseing the folder containing the images?

  • Guy Pucill 23 posts 73 karma points
    May 11, 2014 @ 12:42
    Guy Pucill
    0

    Right now the end user has to type in the folder ID into a textfield data type. I would rather have the user pick a media folder of choice. Both Media pickers cannot choose media folders only media images. The Content Picker can only choose document types from content.

  • Guy Pucill 23 posts 73 karma points
    May 11, 2014 @ 12:50
    Guy Pucill
    0

    Sorry my bad. I need to get used to the new 7 UX. The data type of choice is Media Picker and the user just needs to choose the grey "select" text under the folder icon. I was clicking on the actual folder icon.

  • Torben Warberg Rohde 35 posts 89 karma points
    May 13, 2014 @ 13:03
    Torben Warberg Rohde
    0

    I was strugling with the same issue. Maybe the text should read "select folder" instead.

  • Eduardo Sobrinho 18 posts 38 karma points
    Nov 24, 2014 @ 20:06
    Eduardo Sobrinho
    0

    Hi guys! I have the same problem too!

    Sorry for my bad English. I am Brazilian and I do not speak English.

    In umbraco 6.x we could select the folder 'Media' using the data type 'Content Picker' and this returned the 'folder id'. However in U7 apparently this is not possible.

    As I'm not have much time to research a elegant solution I create a personalized doctype 'Media Picker Legacy'. The user must select any file inside de media folder and this field retrieve the 'ID' of the media file. My routine gets the selected media file Id and list theirs sibilings. 

    This works but the solution is very ugly. If anyone have any suggestions I thanks a lot.

    The snipped code below shows an example of the my code:

    var mediaFile = Library.MediaById(mediaId);
    var mediaFolder =  mediaFile.Parent; 

     

     @foreach (var mediaItem in mediaFolder.Children)
    {
    my razor code here listing de sibilings of selected media.
    }

        


  • jivan thapa 194 posts 681 karma points
    Nov 25, 2014 @ 07:45
    jivan thapa
    3

    Well, You can create a new Data type. Section>Developer=>Data types=> Create new with following options. enter image description here

  • Paul 184 posts 646 karma points
    Mar 03, 2017 @ 09:43
    Paul
    0

    Thanks for posting this, I was trying to achieve the same result with a custom controller and having a nightmare ! This enabled me to achieve the same result very very quickly. I just wish I'd spotted it a couple of days ago!

    Thanks anyhow !

  • Rob Scott 41 posts 94 karma points
    May 29, 2015 @ 20:59
    Rob Scott
    0

    Old post - using Umbraco 6.2

    Add property "Media Picker" to doc type. In the content, pick the folder.

    DynamicPublishedContent yourFolder = Umbraco.Media(CurrentPage.GetProperty("nameOfYourProperty").Value.ToString());
    foreach (var media in approvedFolder.Children)
    {
            string umbracoImageFileName = media.GetPropertyValue<string>("umbracoFile");
            string umbracoImageExtension = media.GetPropertyValue<string>("umbracoExtension");
            var thumnail = string.Concat(umbracoImageFileName.Substring(0, (umbracoImageFileName.Length - umbracoImageExtension.Length - 1)), "_thumb.jpg");
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft