I am trying to make a "library" iterate the folders of a parent Media Folder called "biblioteket". For each of these folders i want to create a link into a page where the folders' name is the headline and all the PDF files in the Folder are shown as items.
My problem seems to be in creating a parent Media file through which i can iterate.
What I want to create is a for each loop that iterates all the media elements in a folder. As far as i could see i needed to use the "MediaService" and it gave me an error. So what i have now is this:
Eg. parent folder "Biblioteket" > "Mappe1" - "Mappe1" Then contains several .pdf files. I want to create a div for each of these pdf files which has an tag that opens the pdf file in a _blank
first of all if you just want to display media items on frontpage of your website then don't use the MediaService. It goes to the database and should not used for frontend actions.
Have a look at the Umbraco.TypedMedia() helpers to query for media items.
Both of you are leading me the right way!! Thank you! I am so close now.
However, the code you provided Alex only iterate and display through the folders within "Biblioteket". I need the template of this node to display the content of a folder that is within the "Bibliotek".
The "vaelgMediaMappe" is a Field of datatype Media Picker, where my future client has to choose the folder in which the pdf documents they want to show is located.
How do i get to iterate through the files in the "vaelgMediaMappe" folder ?
Include .dll - where?
Hi there,
I am trying to use Media Service (https://our.umbraco.org/Documentation/Reference/Management/Services/MediaService)
What i stumbled upon was where to include:
"Umbraco.Core.dll"
as it says i have to. Can anyone help me with this?
Kind regards Magnus
Hi Magnus,
Can you explain what you are trying to do? If you are using Umbraco, the Umbraco.Core dll will already be included in your project.
Thanks,
Nik
Hi there Nik,
Thank you for your answer.
I am trying to make a "library" iterate the folders of a parent Media Folder called "biblioteket". For each of these folders i want to create a link into a page where the folders' name is the headline and all the PDF files in the Folder are shown as items.
My problem seems to be in creating a parent Media file through which i can iterate.
Is this anything you can help with?
Thank you - Magnus
Hi Magnus,
Try to crate media folder, what exactly is the problem?
Hi Alex,
I have created the media folder.
What I want to create is a for each loop that iterates all the media elements in a folder. As far as i could see i needed to use the "MediaService" and it gave me an error. So what i have now is this:
Eg. parent folder "Biblioteket" > "Mappe1" - "Mappe1" Then contains several .pdf files. I want to create a div for each of these pdf files which has an tag that opens the pdf file in a _blank
see this for better understading:
http://maggerit-development.dk/filurens-bibliotek/ + http://maggerit-development.dk/filurens-bibliotek/ny-dansk-dramatik/
i want the "Ny Dansk Dramatik" page to load all the pdf files in a folder as the "Fil 1 test".
Sorry if this is not well described, please feel free to ask if you dont get it. And thank you for your time!
kind regards, Magnus
Hi Magnus,
As I understand you need something like:
This code renders urls all medias under Biblioteket root node in media section. I hope it will help you.
Thanks,
Alex
Hi Magnus,
first of all if you just want to display media items on frontpage of your website then don't use the MediaService. It goes to the database and should not used for frontend actions.
Have a look at the Umbraco.TypedMedia() helpers to query for media items.
Regards David
Hi Alex and David,
Both of you are leading me the right way!! Thank you! I am so close now.
However, the code you provided Alex only iterate and display through the folders within "Biblioteket". I need the template of this node to display the content of a folder that is within the "Bibliotek".
I have tried this, but it doesnt work:
The "vaelgMediaMappe" is a Field of datatype Media Picker, where my future client has to choose the folder in which the pdf documents they want to show is located.
How do i get to iterate through the files in the "vaelgMediaMappe" folder ?
Thank you so much for your time and help,
Kind Regards, Magnus
Hi Magnus,
Try this code, we are close:) :
Thanks,
Alex
Hi Magnus,
What Alex has produced looks pretty good, however an alternative would be to create a recursive function that allows for potentially infinite depth.
I would looks at extracting the middle of the outer foreach loop like this:
Then this can be called like this:
You could extend this to limit the depth it works to as well by having a level option as IPublishedContent has a level indicator against it.
Hey Alex and Nik,
IT WORKS! :D
I tweaked Alex' code a bit in order for it to do it right, so the code is now:
I can see the possibilites in your response Nik, and i will save it for further use! :D
Thank you all very much! It has been a really big help!
Kind regards, Magnus
Magnus, we are really happy to help!!!
Thanks
is working on a reply...