This creates a link to the document, but the problem is that the link label is also rendered as the relative path to the Media Library, while I only need the name of the file and it's file extension
so in stead of rendering '/media/1395/mydocument.docx' as label for the link, how can I make it render 'mydocument.docx'
how to get filename for document stored with DAMP
Hi,
I'm using DAMP for storing documents (doc, docx, pdf) in the Media Library.
To render a link to the document on the page, I use this Razor script:
@if (@Model.HasValue("activityDownload"))
{
var document = @Model.activityDownload.mediaItem.ActivityDocument.umbracoFile;
<p>Download : <a href="@document">@document</a></p>
}
This creates a link to the document, but the problem is that the link label is also rendered as the relative path to the Media Library, while I only need the name of the file and it's file extension
so in stead of rendering '/media/1395/mydocument.docx' as label for the link, how can I make it render 'mydocument.docx'
Thanks for your help,
Anthony
I solved it like this:
@if (@Model.HasValue("activityDownload"))
{
var document = @Model.activityDownload.mediaItem.ActivityDocument.umbracoFile;
string[] filename = document.Split(new char[]{'/'});
<p>Download : <a href="@document">@filename[3]</a></p>
}
I was hoping that there just might be a handy Umbraco.Library helper method.
Greetings,
Anthony
The path is /media/1395/mydocument.docx so that is what DAMP returns. If you want the filename you can do this:
This is not related to DAMP, but just a standard piece of C# to get the filename.
Jeroen
Hi Jeroen,
thanks, your solution is more concise then my string.split() solution
Thanks a lot,
Anthony
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.