I've created this razor scripts, which gives me all the files from within a specific mediafolder. It works okay but it could be better.
My problem is that part of the code don't work because that part is only relevant for PDF's, since I use the package PDF thumbnails which creates a folder inside the mediafolder called pdfthumbs in which I will get the first thumbnail of the pdf.
So in my if statement i need a conditions to check for either the file extension or, if the pdfThumbs folder exist in the mediafolder?
Any help will be much appreciated.
foreach(dynamic pdfs in mediaFolder.file){ var pdf = PDFHelper.GetMedia(pdfs.Id); var pdfUrl = pdf.Media.Url; var c = 0; string documentUrl = @pdfUrl; <div class="element-item">
<a target="_blank" href='@documentUrl1'> @if (CONDITION to insert?){
foreach (var thumb in pdf.PdfThumbs){ if(c > 0){break;} <img width="90" src="@thumb.fileName"> c++; } <span>@pdf.Media.name</span> } </a> </div> }
Not sure how PDFHelper.GetMedia(pdfs.Id) works. You can try this one
var pdf = ApplicationContext.Current.Services.MediaService.GetById(pdfs.Id);
if (pdf.HasProperty("umbracoExtension") && !string.IsNullOrEmpty(pdf.GetValue("umbracoExtension").ToString()))
{
if(pdf.GetValue("umbracoExtension").ToString().Equals("pdf"))
{
@pdf.Name
}
}
Check for file extension in mediafolder - razor
Hi All,
I've created this razor scripts, which gives me all the files from within a specific mediafolder. It works okay but it could be better.
My problem is that part of the code don't work because that part is only relevant for PDF's, since I use the package PDF thumbnails which creates a folder inside the mediafolder called pdfthumbs in which I will get the first thumbnail of the pdf.
So in my if statement i need a conditions to check for either the file extension or, if the pdfThumbs folder exist in the mediafolder?
Any help will be much appreciated.
foreach(dynamic pdfs in mediaFolder.file){var pdf = PDFHelper.GetMedia(pdfs.Id);
var pdfUrl = pdf.Media.Url;
var c = 0;
string documentUrl = @pdfUrl;
<div class="element-item"> <a target="_blank" href='@documentUrl1'>
@if (CONDITION to insert?){ foreach (var thumb in pdf.PdfThumbs){
if(c > 0){break;}
<img width="90" src="@thumb.fileName">
c++;
}
<span>@pdf.Media.name</span>
}
</a>
</div>
}
Hi Bjørn,
You could use the following method to see if the file has a PDF extension:
Thanks, Dan.
What type is mediaFolder and what type is MediaFolder.File.
If you create a new Media or IMedia object that has a property on i think its called Extension which will give you the file extension :).
Hope this helps ,
Charlie :)
Not sure how PDFHelper.GetMedia(pdfs.Id) works. You can try this one
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.