1

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(???)
serge
  • 13,940
  • 35
  • 121
  • 205
  • Here's some documentation about the UmbracoHelper that you might find useful: [https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/](https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/) – Rob Purcell Apr 29 '15 at 10:02

2 Answers2

2

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

alimac83
  • 2,346
  • 6
  • 34
  • 50
1

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(...)
codekaizen
  • 26,990
  • 7
  • 84
  • 140
bowserm
  • 1,046
  • 10
  • 25