Get complete listing of all Media files with .doc and .pdf extensions
I would like to pull a list of all the Media files with .doc and .pdf extensions using a Razor Macro in Umbraco 6.1.6, but I am not quite sure of how to accomplish this.
Could someone make some suggestions? Thanks!
Here is what I have so far, but it fails with errors.
@{
var MediaFolder = Library.NodeById(Parameter.mediaFolder);
var media = Model.MediaById(MediaFolder);
var files = media.Children;
}
@{
foreach(var file in files)
{
var fileUrl = file.umbracoFile;
if(file.umbracoExtension == "pdf")
{
<a href="@fileUrl">
@file.Name @file.umbracoExtension
</a>
}
if(file.umbracoExtension == "doc")
{
<a href="@fileUrl">
@file.Name @file.umbracoExtension
</a>
}
else
{
<p>not a document</p>
}
}
}
I have tested this on a Umbraco 6.1.6 If you go to developer section and create a partial view marco file, then you can use the code snippet from my previous post.
Using my original code I can get the top level media items, but nothing else. If I change my files variable to be media.Descendants() the script won't even load. What's up with that?
Get complete listing of all Media files with .doc and .pdf extensions
I would like to pull a list of all the Media files with .doc and .pdf extensions using a Razor Macro in Umbraco 6.1.6, but I am not quite sure of how to accomplish this.
Could someone make some suggestions? Thanks! Here is what I have so far, but it fails with errors.
Hi Steve,
I think something like this will do what you are after.
Hope this helps,
/Dennis
Thanks for your suggestion Dennis, but I am using Webforms, not using MVC
Hi Steve,
I have tested this on a Umbraco 6.1.6 If you go to developer section and create a partial view marco file, then you can use the code snippet from my previous post.
/Dennis
When I try to create a partial view like you suggest, I get a system error within the backend.
Okay perhaps you can find more info on why you are getting this in the log file
/App_Data/Logs
/Dennis
Using my original code I can get the top level media items, but nothing else. If I change my files variable to be media.Descendants() the script won't even load. What's up with that?
is working on a reply...