Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    May 09, 2012 @ 15:19
    Anthony Candaele
    0

    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 <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

  • Anthony Candaele 1197 posts 2049 karma points
    May 09, 2012 @ 15:57
    Anthony Candaele
    0

    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

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    May 09, 2012 @ 16:00
    Jeroen Breuer
    1

    The path is /media/1395/mydocument.docx so that is what DAMP returns. If you want the filename you can do this:

    @using System.IO;
    var document = Path.GetFileName(Model.activityDownload.mediaItem.ActivityDocument.umbracoFile);

    This is not related to DAMP, but just a standard piece of C# to get the filename.

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    May 09, 2012 @ 16:18
    Anthony Candaele
    0

    Hi Jeroen,

    thanks, your solution is more concise then my string.split() solution

    Thanks a lot,

    Anthony

  • 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.

Please Sign in or register to post replies