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)?
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?
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
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.
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?
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.
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.
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?
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.
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
Hi Amir,
What version of Umbraco are you using?
Jeavon
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
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
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.
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?
Yep, it is.
The documents require frequent updates for filings, quarterly reports, etc.
Strange I can't replicate at all with v6.1.6
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?
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.
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.
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 :)
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.
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.
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.
is working on a reply...