Hi. I have this problem. In the Media Section i have a folder called "pdf" and another folder in the pdf folder called "news". In the news folder i have oploaded a few pdf's which i want to be displayed on my website
Hope there is someone out there there can help me.
If you´re using Webforms, here is a way that you could do it,
On the document type create a field of the data type media picker and give it a name and an alias. Then the user picked the folder called news. With this code below you will display the files in the news folder.
@inherits umbraco.MacroEngines.DynamicNodeContext
@if (Model.HasValue("Alias")){
var MediaFolder = Library.NodeById(Model.Alias);
foreach(var file in MediaFolder.Children){ var fileUrl = file.umbracoFile;
<a href="@imageUrl"> @file.Name </a>
} }
If you want to show the extension of the file too it can be done like this:
@if (Model.HasValue("Alias")){
var MediaFolder = Library.NodeById(Model.Alias);
foreach(var file in MediaFolder.Children){ var fileUrl = file.umbracoFile;
Hope this can help you, remember tochangethe locationswhere Ihave writtenAlias. Change it so it match the alias of your field on the document type where the user has to pick the folder.
That´s okay. I will try to explain it more detailed then.
I assumeyou are using Webforms and macro scripts, if so. Find the page at you want to show the list of the PDF files. Then find the document type for that type of page. You will find the document types under the settings sections -- > document types.
Then add a new propperty to the document type, give a name and it will get an alias. Choose the field to be a type of media picker. When you have done that save the document type. Go to the developer section, create a clean scripting file with a associated macro file. In the scripting file pasted this code in.
@if(Model.HasValue("Alias")){
var MediaFolder = Library.NodeById(Model.Alias);
foreach(var file in MediaFolder.Children){ var fileUrl = file.umbracoFile;
<a href="@fileUrl"> @file.Name </a>
} }
Remember tochange Alias so it match your alias of the file on document type. e.g if you name of the field is: Pick Files it will get an alias of pickFiles. So all the places where I have wrote Alias you have to change it to. Model.HasValue("pickFiles").
If you want the list to print the extention of the file you could use e.g the name would be your name of the file.pdf
@if(Model.HasValue("Alias")){
var MediaFolder = Library.NodeById(Model.Alias);
foreach(var file in MediaFolder.Children){ var fileUrl = file.umbracoFile;
When you have created the scription file with the associated macro file go back to the settings section, find the template for the page you want the list of your file to appear and insert the macro. e.g or use the Umbraco backoffice to insert the macro. Then go to the content section, choose the a page with new field, Then pick the news folder with the new media picker field, and it will list the files in the folder.
I don´t hopethat this post is too detailed, butmakes more sensenowto you.
Show list of PDF's in Razor
Hi. I have this problem. In the Media Section i have a folder called "pdf" and another folder in the pdf folder called "news". In the news folder i have oploaded a few pdf's which i want to be displayed on my website
Hope there is someone out there there can help me.
Hi Høgni,
If you´re using Webforms, here is a way that you could do it,
On the document type create a field of the data type media picker and give it a name and an alias. Then the user picked the folder called news. With this code below you will display the files in the news folder.
If you want to show the extension of the file too it can be done like this:
Hope this can help you, remember to change the locations where I have written Alias. Change it so it match the alias of your field on the document type where the user has to pick the folder.
/Dennis.
Hi thank you for the quick answer... I'm still pretty new to this :/
I dont quite understand your answer
/Hogni
Hi Hogni,
That´s okay. I will try to explain it more detailed then.
I assume you are using Webforms and macro scripts, if so. Find the page at you want to show the list of the PDF files. Then find the document type for that type of page. You will find the document types under the settings sections -- > document types.
Then add a new propperty to the document type, give a name and it will get an alias. Choose the field to be a type of media picker. When you have done that save the document type. Go to the developer section, create a clean scripting file with a associated macro file. In the scripting file pasted this code in.
Remember to change Alias so it match your alias of the file on document type. e.g if you name of the field is: Pick Files it will get an alias of pickFiles. So all the places where I have wrote Alias you have to change it to. Model.HasValue("pickFiles").
If you want the list to print the extention of the file you could use e.g the name would be your name of the file.pdf
When you have created the scription file with the associated macro file go back to the settings section, find the template for the page you want the list of your file to appear and insert the macro. e.g or use the Umbraco backoffice to insert the macro. Then go to the content section, choose the a page with new field, Then pick the news folder with the new media picker field, and it will list the files in the folder.
Hi thanks againg for the great answer :) just that i cant get the URL to work :/
{
}
/Hogni
Does @fileUrl.Url work?
nope :/
is working on a reply...