Copied to clipboard

Flag this post as spam?

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


  • Chris C 43 posts 184 karma points
    Dec 03, 2013 @ 07:12
    Chris C
    0

    Getting media descendants in folder>subfolder

    Hello again.  I'm truly stumped this time.  I have a structure of media folders like this -

    Main Gallery Folder > Sub Folders > The Media Items (Photos)

    And I have a Razor macro that is supposed to go through all the photos (regardless of which folder they are in) and pull the twelve newest items. Here's the simplified code -

    // 1129 is the id of the "main gallery folder"
    dynamic mediaFolder = new umbraco.MacroEngines.DynamicMedia(1129);
    @foreach (var photo in mediaFolder.Descendants("Image").OrderBy("CreateDate desc").Take(12))
      {
         <li>
            <a href="@photoPageUrl" title="View photo, '@photo.Name'">
               <img alt="@photo.Name" src="@photo.Url" /></a></li>
      }

    It was working fine before, but now, when I add new media items in the subfolders, they don't show up...  If I move them directly below the "main gallery folder" they do show up! 

    So why, all of a sudden, is the Descendants method not searching the subfolders? Thanks for any help! 

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 03, 2013 @ 08:35
    Fuji Kusaka
    0

    Hi Chris,

    So you want to display 12 Latest Image present regardless of the Folder it lies ?

    @using umbraco @using System; @using umbraco.MacroEngines; @using umbraco.BusinessLogic @using System.Collections.Generic; @using umbraco.cms.businesslogic.media; @{ dynamic mediaFolder = new DynamicMedia(1143); foreach(dynamic photo in mediaFolder.Descendants("File").OrderBy("CreateDate, desc").Take(12)){ @photo.Name <br/> } }
  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 03, 2013 @ 09:05
    Fuji Kusaka
    0

    Sorry again here it is and works well for me

    @using umbraco
    @using System;
    @using umbraco.MacroEngines;
    @using umbraco.BusinessLogic
    @using System.Collections.Generic;
    @using umbraco.cms.businesslogic.media;
    @{
    dynamic mediaFolder = new DynamicMedia(1143);
    foreach(dynamic photo in mediaFolder.Descendants("File").OrderBy("CreateDate, desc").Take(10)){
    @photo.Name <br/>
    }
    }
  • Chris C 43 posts 184 karma points
    Dec 03, 2013 @ 17:14
    Chris C
    0

    Yes, that should work.  But it doesn't pull any new images that I upload. 

    I did some more digging to find out why it's stopped working "all of a sudden".  Turns out that it has to do with the subfolders themselves.  The existing subfolders I created a while ago, during a slightly older version of Umbraco.  But if I upload images into new folders that I create now, then they don't show up in the query. 

    Is there a way to go behind the scenes and see if there is some difference with the folder structure? 

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 03, 2013 @ 17:37
    Fuji Kusaka
    0

    Weird i have the following working under v4.11.8 and using this structure under Media Section

    MediaFolder (id = 1143)
    Folder 1 
    img 1
    img 2
    Folder 2
    Img 1
    Folder 3
    Img 1 

    Are you using the Media Type "Image" ? or any other within the folder ?

  • Chris C 43 posts 184 karma points
    Dec 03, 2013 @ 17:57
    Chris C
    0

    That's the basic structure I have too. All my docTypes are the defaults. 

    Further narrowed the issue down a bit...  I remembered that I started using a new user account a while ago.  At the beginning I was using the built-in admin account.  Then I made another account, with admin permissions. 

    So when I create media folders using my new account, the images don't show up in the query.  When I log in using the built-in account and update the folders, then the images will show up. 

    Is there a way to fix that? 

  • Chris C 43 posts 184 karma points
    Dec 03, 2013 @ 18:51
    Chris C
    0

    Sorry to confuse the issue with all the posts. 

    But the basic problem is that when I create or update a media folder with any account besides the default, first admin account, the contents don't show up in queries. 

    Also, I should mention that this is Umbraco 6.1.6. 

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 04, 2013 @ 20:26
    Jeavon Leopold
    0

    I wonder if this issue is causing your problem as DynamicMedia is using Examine under the hood.

    Maybe try stopping you application pool, delete the Examine indexes so they are refreshed on start and see if the items appear?

    Jeavon

  • Chris C 43 posts 184 karma points
    Dec 04, 2013 @ 23:12
    Chris C
    0

    The items only disappear if I use a specific account to create / update. Also, it displays the same behavior in development and on the production server. 

    But I suppose it's worth a shot...  What is Examine and how do I delete the indices? 

     

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Dec 04, 2013 @ 23:24
    Jeavon Leopold
    100

    Hi Chris,

    This is very odd behaviour going on.

    Examine is an underlying search engine and is used by DynamicMedia for caching

    Examine indexes are found in \App_Data\TEMP\ExamineIndexes\

    • Stop your application pool (otherwise the indexes are locked and cannot be deleted)
    • Delete all sub folders and contents in the ExamineIndexes folder
    • Restart application pool and the indexes will be recreated
    • See if your items turn up

    Worth a try but if the same thing is happening in both development and production it is unlikely this is the problem.

    One other thing to try is to check that when you create folders in media that you then click the properties tab and then click the save button as the create action only doesn't fully save and the save button isn't shown in the default "contents" view.

    Jeavon

  • Chris C 43 posts 184 karma points
    Dec 09, 2013 @ 17:29
    Chris C
    0

    The problem went away after a while...  So no clue. 

    But thanks for the help.  I think going to properties and clicking save again was the fix.  If that's by design, then it'd be nice if there were some indication that the media folder is not published. 

Please Sign in or register to post replies

Write your reply to:

Draft