简体   繁体   中英

Use Content instead of Document in Umbraco (v6)

I would like to update some obsolete code from umbraco v4 in the updated to v6 solution.

I have

entitiesFolder = new umbraco.cms.businesslogic.web.Document(folderId);
entitiesFolder.ReorderChildren(
    entitiesFolder.Children.OrderBy(fdoc => fdoc.Text), 
    refreshEntireCache);

Now the recomendation instead of obsolete Document is to use Umbraco.Core.Models.Content . How? Didn't find (as usual for Umbraco) any documentation about... (

// new version
var toto = new Umbraco.Core.Models.Content(??)
toto.SoirtChildren(???)

Are you doing this from a razor view? If so you can do:

var nodeId = 123;
var myNode = Umbraco.TypedContent(nodeId);
var property = myNode.GetPropertyValue<string>("myStringAlias");

If you're doing it from a class or something you'll have to use something like:

var helper = new UmbracoHelper(UmbracoContext.Current);
var nodeId = 123;
var myNode = helper.TypedContent(nodeId);

(This is untested but it should work..)

If you are just querying data and need to sort it, using the umbracoHelper is a great way to go. It only hits the xml cache in App_Data/umbraco.config, so you don't hit the database.

However, if you are attempting to programatically sort some of the nodes in the content tree, you will need to use the ContentService . You will need to use the ContentService whenever you actually want to programatically modify content nodes. You will also find a similar MediaService for media.

https://our.umbraco.org/Documentation/Reference/Management-v6/Services/ContentService

ApplicationContext.Current.Services.ContentService.Sort(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM