Fixer
Fixer

Reputation: 6095

How to get a content node using Umbraco 5 API

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

Upvotes: 0

Views: 1094

Answers (1)

seraphym
seraphym

Reputation: 1146

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);

Upvotes: 1

Related Questions