This should be simple but I am missing something obvious.
I have a web service and I am getting my documents within it and I need to get the url of an image uploaded via a media picker.
My code is as follows:
foreach(var d in documents)
{
string name = d.GetProperty("documentTitle").Value.ToString();
var media=Umbraco.Medi(d.GetProperty("documentUpload").Value.ToString());
}
I have read in multiple places I should be able to get the media picker by using
you need to either pass or generate a version of the UmbracoHelper class.
in razor views the Umbraco object. is a version of the Umbraco Helper.
it depends a bit on what your webservice is.
if you are inheriting an umbraco controller via UmbracoController or UmbracoApiController (or the authorized versions if your webservice is only for back office use) then you will have an Umbraco object which is the Umbraco Helper.
if not. then the you can create the helper in code
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
and from here you should be able to do umbHelper.Media()
i would also look at .TypedMedia() because that gets you a typed version of the media object, which is slightly better to work with (and i think dynamic types are on the way out)
U7 Get Media URL in C# name spaces?
Hi
This should be simple but I am missing something obvious.
I have a web service and I am getting my documents within it and I need to get the url of an image uploaded via a media picker.
My code is as follows:
I have read in multiple places I should be able to get the media picker by using
But I seem to be missing a name space or something as it never finds "Media" under Umbraco in my code.
I have the following usings:
What am I missing? Or am I doing this wrong?
Any one got any advice to offer?
Hi
you need to either pass or generate a version of the UmbracoHelper class.
in razor views the
Umbraco
object. is a version of the Umbraco Helper.it depends a bit on what your webservice is.
if you are inheriting an umbraco controller via UmbracoController or UmbracoApiController (or the authorized versions if your webservice is only for back office use) then you will have an Umbraco object which is the Umbraco Helper.
if not. then the you can create the helper in code
and from here you should be able to do
umbHelper.Media()
i would also look at
.TypedMedia()
because that gets you a typed version of the media object, which is slightly better to work with (and i think dynamic types are on the way out)Thank you @Kevin!
That was exactly what I needed.
is working on a reply...