loop through entire content tree ( c# ) Options
tim
Posted: Sunday, December 16, 2007 10:36:56 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Hey Guys,

I'm working on a usercontrol and i want to loop through the entire content tree. How can I do that ?

I Thought I could do it like this
Code:

Document root = new Document(-1);
                        if (root.HasChildren)
                        {
                            loopchildren(root, alias);
                        }


Code:

private void loopchildren(Document ParentDocument, string alias)
        {
            Label1.Text += ParentDocument.Children.Length.ToString();
           
            foreach (Document tempDocument in ParentDocument.Children)
            {
                Label1.Text += tempDocument.Id.ToString();
                if (tempDocument.Id > 0)
                {
                    if (tempDocument.ContentType.Alias == alias)
                    {

                        // Move(tempDocument);
                        Label1.Text += tempDocument.Id.ToString() + "<br/>";
                    }

                    if (tempDocument.HasChildren)
                    {
                        loopchildren(tempDocument, alias);
                    }
                }
            }
           
        }


But that doesn't seem to work.

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
sfxpete
Posted: Monday, December 17, 2007 1:04:41 AM
Rank: Devotee

Joined: 9/5/2007
Posts: 65
Look here...

http://www.umbraco.org/documentation/books/what's-new-in-v3/new-feature-nodefactory-as-datatable-object

Or consider using...

library.GetXmlAll();

...that returns the whole content tree in the standard umbraco XML format. Theres othed library.Get***** functions to return say the XML for the current noade and the like.

Enjoy!
tim
Posted: Monday, December 17, 2007 9:14:22 AM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Thanks for the reply, I considered using the nodefactory but does it also return the nodes that are not published ?

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Monday, December 17, 2007 9:21:44 AM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
The nodefactory (in the umbraco.presentation.nodeFactory namespace) is a wrapper for the in-memory XML for much easier access to published data from .NET.

I need all data , published and not published.

Any Idea ?

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
hoehler
Posted: Monday, December 17, 2007 1:10:54 PM

Rank: Addict

Joined: 7/19/2006
Posts: 597
Location: Bad Homburg, Germany
Then use the document in umbraco.cms.businesslogic.web
eg: umbraco.cms.businesslogic.web.Document doc = new umbraco.cms.businesslogic.web.Document(id);
doc.Published, doc.Children, etc...

hth, Thomas


• 2007/2008 MVP • www.thoehler.com • Bad Homburg, Germany
tim
Posted: Monday, December 17, 2007 1:12:56 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Yup that is what i tried, but how can i get the entire structure, i thought if I used -1 as id it returned the root document but that doesn't seem to work

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
hoehler
Posted: Monday, December 17, 2007 1:21:13 PM

Rank: Addict

Joined: 7/19/2006
Posts: 597
Location: Bad Homburg, Germany
Sorry, didn't read the whole thread.

Use umbraco.cms.businesslogic.web.Document.GetRootDocuments to get a list of all root documents of the backend and then iterate through the structure by document.Children...

hth, Thomas

• 2007/2008 MVP • www.thoehler.com • Bad Homburg, Germany
tim
Posted: Monday, December 17, 2007 1:22:53 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Yup that did the trick. Didn"t notice the method. Thanks !

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.