I need some guidance with getting archetype values via the API (compiling a dll);
I can run the following code in Razor and it works just fine.
var inventRoot = Umbraco.Content(1100);
foreach (var inventory in inventRoot.Descendants("course")){
var entries = inventory.GetPropertyValue<Archetype.Models.ArchetypeModel>("propertyX");
..
}
Then I tried to implement it in the .CS (api usage to compile as dll) and realized
.Descendants("course") was not working even though i have included using Umbraco.Web.
It was giving error "IContent does not contain definition for 'Descendants' "
So I have tried another approach (IContent vs IPublishedContent is not very clear to me yet) to iterate all the inventory items via
ContentService.GetContentOfContentType(1081)
where 1082 is the Id of the document type "course"
using Umbraco.Core;
using Umbraco.Web;
using Archetype;
using Archetype.Models;
using Archetype.Extensions;
var inventories = global::Umbraco.Core.ApplicationContext.Current.Services.ContentService.GetContentOfContentType(1081);
foreach (var inventory in inventories)
{
var entries = inventory.GetValue<Archetype.Models.ArchetypeModel>("propertyX");
^--here throws exception "The given key was not present in the dictionary."
}
which seems to iterate all the "course" nodes but throws exception while reading the Archetype with GetValue
Can someone shed light on how to read archetype property/values for all descendants of a node via the api properly?
The ContentService (which will return IContent objects) is basically for manipulating values in the backoffice database (eg. CRUD operations) rather than the fastest way to retrieve data to display on your published website.
Your published website should use the UmbracoHelpers to query Umbraco Content, and these will return instances of IPublishedContent, from the Umbraco Cache rather than the database.
You can still reference the Umbraco. helpers in a c# class library by instantiating the helper like so:
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
var inventRoot = umbracoHelper.Content(1100);
ContentService.GetContentOfContentType GetValue ArcheType
I need some guidance with getting archetype values via the API (compiling a dll);
I can run the following code in Razor and it works just fine.
Then I tried to implement it in the .CS (api usage to compile as dll) and realized
.Descendants("course") was not working even though i have included using Umbraco.Web.
It was giving error "IContent does not contain definition for 'Descendants' "
So I have tried another approach (IContent vs IPublishedContent is not very clear to me yet) to iterate all the inventory items via
ContentService.GetContentOfContentType(1081) where 1082 is the Id of the document type "course"
which seems to iterate all the "course" nodes but throws exception while reading the Archetype with GetValue
Can someone shed light on how to read archetype property/values for all descendants of a node via the api properly?
Hi Keilo
The ContentService (which will return IContent objects) is basically for manipulating values in the backoffice database (eg. CRUD operations) rather than the fastest way to retrieve data to display on your published website.
Your published website should use the UmbracoHelpers to query Umbraco Content, and these will return instances of IPublishedContent, from the Umbraco Cache rather than the database.
You can still reference the Umbraco. helpers in a c# class library by instantiating the helper like so:
is working on a reply...