I have a usercontrol (.net) that creates pages. I would like to sort the pages when done. To make it even more difficult I would like to sort by name, but put a specific page as the first (like an index-page). How do I do that? I’m using the nodefactory in V4 Second question: is it possible to reload the content tree, in the backendm from the usercontrol, after the sort is made?
Im not sure how you are doing this with the NodeFactory as it read only. Dont you mean umbraco.cms.businesslogic.web?
Anyhow to sort nodes throught the API look at the documents SortOrder property. This is an interger value to set the sort position relative to its siblings SortOrder property.
You would need to get the sibling document collection via the parents children property and then sort the array by the first name. You will need to write your own sorting code but there is plenty of stuff out there on the web on sorting arrays. After this you would then need to set the SortOrder property of each of those documents and save them back to the db.
The next time the tree is loaded in the admin it would have your new docs in the new order.
How to sort nodes from .net usercontrol?
I have a usercontrol (.net) that creates pages. I would like to sort the pages when done. To make it even more difficult I would like to sort by name, but put a specific page as the first (like an index-page). How do I do that?
I’m using the nodefactory in V4
Second question: is it possible to reload the content tree, in the backendm from the usercontrol, after the sort is made?
Im not sure how you are doing this with the NodeFactory as it read only. Dont you mean umbraco.cms.businesslogic.web?
Anyhow to sort nodes throught the API look at the documents SortOrder property. This is an interger value to set the sort position relative to its siblings SortOrder property.
You would need to get the sibling document collection via the parents children property and then sort the array by the first name. You will need to write your own sorting code but there is plenty of stuff out there on the web on sorting arrays. After this you would then need to set the SortOrder property of each of those documents and save them back to the db.
The next time the tree is loaded in the admin it would have your new docs in the new order.
I know I havent given any code but there should be enough for you to get started. There are some gems on saving documents to the database no this wiki page. http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties
is working on a reply...