looking for some advice into how i can efficiently get hold of the images in the results of my TypedContentAtXPath query, here is my code:
string query = $"//homePage/demosHome/demo[@isDoc and number(translate(demoDate,'-T:','')) < '{String.Format("{0:yyyyMMddHHmmss}", enddate)}' and number(translate(demoDate,'-T:','')) > '{String.Format("{0:yyyyMMddHHmmss}", startdate)}']";
var demos = Umbraco.TypedContentAtXPath(query).ToList();
//var homenode7 = Umbraco.TypedContentAtXPath($"//homePage/demosHome/demo[@isDoc and number(translate(substring(demoDate,1,10),'-','')) < number({String.Format("{0:yyyyMMdd}", enddate)})]").ToList();
//var homenode8 = Umbraco.TypedContentAtXPath($"//homePage/demosHome/demo[@isDoc and number(translate(demoDate,'-T:','')) < '{String.Format("{0:yyyyMMddHHmmss}", enddate)}' and number(translate(demoDate,'-T:','')) > '{String.Format("{0:yyyyMMddHHmmss}", startdate)}']").ToList();
return demos
//.Cast<DynamicPublishedContent>()
.Select(d => new Demo {
Date = Convert.ToDateTime(d.GetProperty("demoDate").Value),
Title = (string)d.GetProperty("demoTitle").Value,
Url = d.Url//,
//ImageUrl = d.GetProperty<>("demoImage").HasValue ? d.GetProperty<IPublishedContent>("demoImage").Value
}
)
.ToList();
basically, im trying to populate the ImageUrl property of my return class from within the select part, the only thing is, im not sure what i need to cast the object to, to get hold of the image properties, i can see them in the debugger but they are part of the Umbraco.Web.PublishedContentModels namespace that i cant seem to get hold of.
could anybody advise how i can get the Url property of the image in the demoImage property of my document type?
i get the error:
'IPublishedProperty' does not contain a definition for 'Url' and no extension method 'Url' accepting a first argument of type 'IPublishedProperty' could be found (are you missing a using directive or an assembly reference?)
i have the CoreValueconverters package installed but that only seems to affect properties on the view (Model.Content and CurrentPage) rather than in the code behind or in this case, the APIController.
TypedContentAtXPath and Images
Hi everyone,
looking for some advice into how i can efficiently get hold of the images in the results of my TypedContentAtXPath query, here is my code:
basically, im trying to populate the ImageUrl property of my return class from within the select part, the only thing is, im not sure what i need to cast the object to, to get hold of the image properties, i can see them in the debugger but they are part of the Umbraco.Web.PublishedContentModels namespace that i cant seem to get hold of.
could anybody advise how i can get the Url property of the image in the demoImage property of my document type?
ImageUrl = d.GetPropertyValue
But you will have to use the Our.Umbraco.CoreValueConverters package (nuget or otherwise) unless you are using 7.6 beta.
i tried what you said, but when i do:
i get the error: 'IPublishedProperty' does not contain a definition for 'Url' and no extension method 'Url' accepting a first argument of type 'IPublishedProperty' could be found (are you missing a using directive or an assembly reference?)
i have the CoreValueconverters package installed but that only seems to affect properties on the view (Model.Content and CurrentPage) rather than in the code behind or in this case, the APIController.
is the only way to do it to use dynamics?
Spot the differences: I use GetPropertyValue instead of GetProperty
d'oh, now i see, i had to tweak your example a bit but i ended up with this:
i'm hoping thats the correct way of doing it, but it works
many thanks for the help though
is working on a reply...