Hi, I'm working on updating a v7 site to v8 and having trouble re-using some code that locates the root node and then queries descendants based on various characteristics. This is in a C# class file so had been using the UmbracoHelper - such as helper.ContentAtRoot().First() - which seems like it doesn't work in Umbraco 8. Does anyone have a suggestion? Thanks, Steve
Hi Alex, Thanks for the reply. In this case when I use 'Model' I get an error 'The name Model does not exist in the current context'. I'm not in a view but instead writing some utility/task code to run on a schedule using something like Hangfire.
I can't seem to figure out how to get the current context in Umbraco 8 or how to adapt other suggestions that I've come across such as this post. At this point I don't know if I'm simply missing a reference or just not going about acquiring the current context correctly.
private readonly IUmbracoContextFactory _umbracoContextFactory;
public void DoIt(PerformContext context)
{
UmbracoContextReference contextReference = _umbracoContextFactory.EnsureUmbracoContext();
var myContent = contextReference.UmbracoContext.Content.GetAtRoot().FirstOrDefault();
}
Returns an 'Object Reference not set to instance of an object' error
Hi everyone, Still working out how Umbraco 8 and Hangfire work together but this Our Forum post proved to be very helpful. Does anybody know where can we (who don't already know) can learn how to do this with Dependency Injection? Thanks everyone! Steve
Query content nodes in Umbraco 8
Hi,
I'm working on updating a v7 site to v8 and having trouble re-using some code that locates the root node and then queries descendants based on various characteristics. This is in a C# class file so had been using the UmbracoHelper - such as helper.ContentAtRoot().First() - which seems like it doesn't work in Umbraco 8.
Does anyone have a suggestion?
Thanks, Steve
Hi Steve
I think this code should work:
Thanks,
Alex
Hi Alex,
Thanks for the reply.
In this case when I use 'Model' I get an error 'The name Model does not exist in the current context'.
I'm not in a view but instead writing some utility/task code to run on a schedule using something like Hangfire.
I can't seem to figure out how to get the current context in Umbraco 8 or how to adapt other suggestions that I've come across such as this post.
At this point I don't know if I'm simply missing a reference or just not going about acquiring the current context correctly.
Returns an 'Object Reference not set to instance of an object' error
Steve
Hi everyone,
Still working out how Umbraco 8 and Hangfire work together but this Our Forum post proved to be very helpful.
Does anybody know where can we (who don't already know) can learn how to do this with Dependency Injection?
Thanks everyone!
Steve
is working on a reply...