Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Apr 04, 2014 @ 20:07
    Amir Khan
    0

    Get Media File by ID from MVC View

    I'm trying to get path to a file by its id in an MVC View, why does "@Umbraco.Media(4086).Url" work for images, where 4086 is the id of an image node but @Umbraco.Media(1234).Url or @Umbraco.Media(1234).umbracoFile doesn't work where 1234 is the id of a file node (pdf)?

     

    -Amir

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 04, 2014 @ 20:14
    Jeavon Leopold
    0

    Hi Amir,

    What version of Umbraco are you using?

    Jeavon

  • Amir Khan 1282 posts 2739 karma points
    Apr 04, 2014 @ 20:16
    Amir Khan
    0

    Hi Jeavon,

    I'm using v6.1.6, which brings me to another point. What's the best way to create a document repository within umbraco where if you update a document in one place, it is reflected globally?

    Thanks,

    Amir

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 04, 2014 @ 20:21
    Jeavon Leopold
    0

    That's very strange, can you check that in the media type that you are using for the file, the upload property alias is umbracoFile?

    I'm not quite sure what you mean by a document repository, but it is quite common practice to have library or settings node that sits outside of your website structure and content is pulled in from there... There is an example of this in the hybrid framework

  • Amir Khan 1282 posts 2739 karma points
    Apr 04, 2014 @ 20:43
    Amir Khan
    0

    Confirmed that the Media Type is file, the file is being grabbed from the media section, not from a document property...

    Regarding the repository, I have a serveral documents that are linked to from various places on the site. We need to update each of these links everytime the document is updated. I'm trying to find a way to update them all at one time based on ID or something.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 04, 2014 @ 21:25
    Jeavon Leopold
    0

    Ok and on that file media type is the alias of the upload field "umbracoFile"?

    What do you need to update on all the linked documents?

  • Amir Khan 1282 posts 2739 karma points
    Apr 04, 2014 @ 21:28
    Amir Khan
    0

    Yep, it is.

    The documents require frequent updates for filings, quarterly reports, etc.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 04, 2014 @ 21:45
    Jeavon Leopold
    0

    Strange I can't replicate at all with v6.1.6

    var c = Umbraco.Media(1068);
    var d = c.Url;
    var e = c.umbracoFile;
    

    Both d and e have the url of my PDF. Perhaps try stopping your app pool and deleting your Examine indexes, App_Date/Temp/ExamineIndexes delete all sub folders, start the app pool again. This will check if your indexes maybe be corrupted.

    As far as what I understand on your repository, are you saying you have the same content on many documents and if one is updated you want it to update all of the others?

  • Amir Khan 1282 posts 2739 karma points
    Apr 04, 2014 @ 22:04
    Amir Khan
    0

    Man, none of those work for me. I will try reindeixing.

    Correct on the repository situation. Basically a few pdfs, each referenced from several content pages.

  • Amir Khan 1282 posts 2739 karma points
    Apr 04, 2014 @ 22:06
    Amir Khan
    0

    So, I guess I want to be able to update the PDF globally. The only way I can think of to do it is to use an external service with persistent URLs and swap the documents that way.

  • Charles Afford 1163 posts 1709 karma points
    Apr 05, 2014 @ 14:44
    Charles Afford
    0

    You can use the MediaService(media id) to get the media object.

    Then you want to the umbracoFile property of the mediaobject

    Hope that makes sense.

    Charlie :)

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 05, 2014 @ 15:58
    Jeavon Leopold
    0

    Would be a interesting test to use the MediaService but you shouldn't generally use it for front end rendering as it is not cached. The MediaService is intended to be used for creating, editing and other management tasks not for rendering in Razor views, that what's IPublishedContent accessed through the @Umbraco helper is for.

  • Charles Afford 1163 posts 1709 karma points
    Apr 05, 2014 @ 16:09
    Charles Afford
    0

    But you can create a new Instance of MediaService which exposes the GetMediaById(int id) method?  You could then get the Media Object throught that and then just get the umbracoFile property from it?

    Charlie.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Apr 05, 2014 @ 17:03
    Jeavon Leopold
    0

    Yes you can Charlie, but it's not intended for front end usage as it's not cached and if there was such as thing as unpublished media (there might be one day) you would retrieve the unpublished version of it using the MediaService as you would currently with the ContentService.

Please Sign in or register to post replies

Write your reply to:

Draft