I am trying to create a Media Library and list the documents in a specified Media folder . The following code (Partial View) works very well . But it doesnt display any sub folders . How do i get the list of sub folders to be displayed as well
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@if (Model.MacroParameters["mediaID"] != null)
{
var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaID"]);
Unfortunately it didnt work . I have created the sub folder as a media type from the main folder . I clicked on Main folder , clicked on Create and chose Folder as a Media Type
dynamic mediaFolder = new DynamicMedia(MediaID); if(mediaFolder.Children.Any()){ foreach(dynamic mediaItem in mediaFolder.Children){ if(mediaItem.Where("NodeTypeAlias == \"Folder\"")){ @mediaItem.Name // Here you can make another loop if there is any Image in the Folder }
So if you do this it should display both files and folders
if(mediaFolder.Children.Any()){ int childrenNumber = @mediaFolder.Children.Count(); @childrenNumber // Here you should be getting the number of files and folders present . foreach(dynamic mediaItem in mediaFolder.Children){ @mediaItem.Name } }
Can you please check that your folder has saved by clicking on the properties tab to show the save button and then clicking the save button, I was able to replicate your scenario only by not clicking the save button as it is not shown on the default contents tab.
Great, I can't quite decide if this is a bug or not. Creating a media item is creating a unpublished item, then clicking save publishes it, but of course media doesn't have a unpublished/published state....?
I just encountered this one as well in 6.2.2. Unexpected behaviour. I am looping through all decendants("Image") and trying to pull up all images from sub folders. Decendants("Image") won't go into any folder until you manually save each folder. I'm now looking at how to save 400+ folders without doing this all manually. It would be nice to see a little more love put into the media section (such as right context menu publish or save with children, etc).
Can anyone point me to a save command that I can execute via a razor for each?
Sub Folder Name in Media Library
Hi
I am trying to create a Media Library and list the documents in a specified Media folder . The following code (Partial View) works very well . But it doesnt display any sub folders . How do i get the list of sub folders to be displayed as well
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@if (Model.MacroParameters["mediaID"] != null)
{
var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaID"]);
if(mediaFolder.Children.Any())
{
<ul class = "thumbnails">
@foreach ( var mediaItem in mediaFolder.Children)
{
<li >
<a href = "@mediaItem.umbracoFile" > @mediaItem.Name </a>
</li>
}
<br>
</ul>
}
}
you could try doing something like
Thanks Fuji
Unfortunately it didnt work . I have created the sub folder as a media type from the main folder . I clicked on Main folder , clicked on Create and chose Folder as a Media Type
Can you try something like this instead ?
Thanks Fuji
This bit of line is causing issues ..not sure why
dynamic mediaFolder1 = new DynamicMedia(1293);
If i use this there's no error but the folders are not coming up
dynamic mediaFolder1 = Umbraco.Media(Model.MacroParameters["mediaID"]);
Infact when i do @mediaFolder1.Children.Count() , it shows me only the count of the files and folder's not included in the count
So if you do this it should display both files and folders
Hi Fuji
As i have already stated , if i do @mediaFolder1.Children.Count() , it shows me only the 2 files
Do you think if i assign it to variable , it should show me the folder as well.
No it didnt ..
This
int childrenNumber = mediaFolder1.Children.Count();
@childrenNumber
Still shows the count as 2 . I have 2 files and 1 folder
Hi Arulkumar,
Can you please check that your folder has saved by clicking on the properties tab to show the save button and then clicking the save button, I was able to replicate your scenario only by not clicking the save button as it is not shown on the default contents tab.
Jeavon
Your original Razor Macro Partial View does not have any issue and works perfectly once you have saved the sub folder.
Thanks Jeavon . It worked
Great, I can't quite decide if this is a bug or not. Creating a media item is creating a unpublished item, then clicking save publishes it, but of course media doesn't have a unpublished/published state....?
I just encountered this one as well in 6.2.2. Unexpected behaviour. I am looping through all decendants("Image") and trying to pull up all images from sub folders. Decendants("Image") won't go into any folder until you manually save each folder. I'm now looking at how to save 400+ folders without doing this all manually. It would be nice to see a little more love put into the media section (such as right context menu publish or save with children, etc).
Can anyone point me to a save command that I can execute via a razor for each?
Thanks!
Jamie
is working on a reply...