https://discord.umbraco.com logo
#help-with-umbraco
What service/helper/manager do I use to get the full file path of an media item (v10)?
# help-with-umbraco
z

zimmertyzim_35888

02/11/2024, 11:00 PM
I am having trouble findding the relevant info in the docs. I have a media item (PDF file), I wish to attach this to an email. How can I find the full path of the media item? I am using v10. I have the file as a content model, so I can access the id etc. I used to use umbracoFile to do this, something akin to:
Server.MapPath(trainingLogFile.GetPropertyValue("umbracoFile").ToString());
alas the property is no longert there, or I need to find it via one of the services/helpers. Thanks.
o

osmancoskun_46010

02/12/2024, 7:25 AM
Hi, I search for the similar issue and found the attached code as a replacement for Server.MapPath. I call the function as Website.Controllers.MapPathExtension.MapPath(Context, ldt.Url().ToString()). It works on Umbraco 13 site. I also wonder if this is the correct way to get the physical path for files. Thanks. https://cdn.discordapp.com/attachments/1206374268347088907/1206501192704725022/MapPath.cs?ex=65dc3ccc&is=65c9c7cc&hm=6f9573892b7d7dec2275bd1d1bbe05b619f16578734c9b40b604fa26a2b4a280&
z

zimmertyzim_35888

02/12/2024, 10:20 AM
@Matt Wise - not sure if I am being dense, but is there an example of how to get the actual path? The second example (contents as a stream) is passing in the path of the file, but I don't see where this is actually coming from.
m

Matt Wise

02/12/2024, 10:24 AM
Id have a look see what else is on the MEdiaFile Manager failing that you could use .Url() and swap the slashes 🙂
z

zimmertyzim_35888

02/12/2024, 11:16 AM
Thanks, I'll check that out, but off the top off my head that's just going to give me a normal Url right? I'm not going to be able to use that to read create a stream attach to an email. I'll have a gander.
j

Jason

02/12/2024, 11:33 AM
Yes, you will be able to use a "normal" URL. In Umbraco file filesystem has been abstracted. The idea is that you shouldn't need to know the actual path (because it might not actually be a physical file on the local disk). As Matt points out, using the media file manager to interact with the media item directly is the proper way to do it - it already knows how to follow the URL you provide it to get at the actual file, wherever it is.
z

zimmertyzim_35888

02/12/2024, 11:46 AM
thanks, I'll give this another go.
2 Views