0

I'm an Umbraco newbie and trying to get up to speed. One of the things i'm trying out is the API and accessing a node in the content tree. Unfortunately documentation is a bit thin and i can't find any info covering such a basic task...

I've got a simple content structure

Content > Home > About

How do i retrieve the About node using C# and the API from a plain old model class?

In other CMS's it would be as simple as calling Database.GetItem("/content/home/about")

How is this achieved with Umbraco v5?

Thanks

Fixer
  • 5,985
  • 8
  • 40
  • 58

1 Answers1

1

If you have a single, specific piece of content you want to get it, you can select it using the hiveid like so:

 Umbraco.GetContentById("content://p__nhibernate/v__guid/0000000000000000")

You can find your content id by examining the content's properties from the backoffice.

EDIT:

If you truly must get the content by uri, you could do so by querying the hive. I can't recommend it for performance though.

_context.Application.Hive.QueryContent().Where(x => x.NiceUrl().Equals("/faq/functionality/submit-a-question",StringComparison.InvariantCultureIgnoreCase);
seraphym
  • 1,126
  • 1
  • 8
  • 21
  • Thanks for that - But sometimes you just don't know what the Id is - Anyway to get the content by its path? – Fixer Jun 09 '12 at 02:38
  • I'm trying to do something similar, but I can only see an Umbraco *namespace*. Is `Umbraco` a class? if so: where? – Marc Gravell Jul 04 '12 at 22:20
  • Used here, Umbraco is the helper for the Razor view. If you wanted access to the helper from the backend, instantiate an UmbracoHelper. If you want to get a specific node without the helper, query data from the hive similar to what's shown in the edit, or open a hive reader, and then use GetById on the repository. – seraphym Jul 07 '12 at 21:11