1

I have a strange behaviour on one of my Umbraco 7.3.7 sites. I have a couple of razor macros that loop through folders and files in the media tree and writes out links to view the sub folders or link to the files.

The macro is working fine on the site for a number of days but then for some unknown reason the macros can't find any items in the media tree. If I login to the backend of the site I can browse the media tree and see the files / folders are still there.

I can 'Reload nodes' but this has no effect. Items are still not being displayed by the macro. However if i right click a folder in the media tree and choose 'Sort' then this makes the folder contents visible again in the macro output.

I have to sort each folder in the media tree, sorting the top level folder does not mean content from sub folders is displayed.

The site then runs fine for a few days and then it suddenly happens again and I have to sort all the folders.

Please can anyone help work out what is causing this?

Also is there any way to programmatically loop through all folders in the media tree and perform a sort on each folder so I don't have to go through the manual process of sorting each folder in turn.

@inherits Umbraco.Web.Macros.PartialViewMacroPage


@{ var mediaId = 1062; }

@if (mediaId != null)
{
    @* Get all the media item associated with the id passed in *@
    var media = Umbraco.Media(mediaId);
    var selection = media.Children("Folder");

    if (selection.Any())
    {
        var count = selection.Count();
        var colitems = count / 3;
        var colmod = count % 3;
        if (colmod != 0)
        {
            colitems += 1;
        }
        var loopcount = 1;

        <!--<p>Count: @count @colitems</p>-->
        <div class="row">
            @foreach (var item in selection)
            {
                if (loopcount == 1)
                {
                    @:<div class="col-sm-4">
                        @:<ul class="HomeFolderList">
                }
                <li>
                    <!--<h3><a href="javascript:showChildren(@item.Id);" title="@item.Name">@item.Name</a></h3>-->
                    <h3><a href="/GetCategory/?mid=@item.Id&category=@Server.UrlEncode(item.Name)" title="@item.Name">@item.Name</a></h3>

                    @* GetChildFolders(@item.Id)*@
                </li>

                loopcount += 1;

                if (loopcount == colitems + 1)
                {
                    @:</ul>
                    @:</div>

                    loopcount = 1;
                }


            }
            @* end of for loop, check if we need to close the list and column *@
            @if (loopcount != colitems + 1 && loopcount != 1)
            {
                @:</ul>
                @:</div>
            }
        </div><!-- / row -->

    }
}
  • 1
    Shot in the dark: Try making Umbraco rebuild your indexes by deleting App_Data/TEMP and restarting the App Pool. Back it up first. – glcheetham Mar 03 '16 at 15:13
  • Agreed about the index rebuild (you can also go to Developer >> the Examine management tab >> External Indexer >> Rebuild index). Republishing the site (or just the node giving you issues) helps too (this is essentially what the sort is doing for you - reindexing/republishing) – l.j. cooper Mar 07 '16 at 16:11

0 Answers0