Our Forum has Moved

This site is our old forum and is only here for achive until we get proper 301 redirects setup to make Google happy.

Please use our new community site - Our Umbraco - which contains an improved forum, documentation wiki, package repository and a member locator.

Go to Our Umbraco now

Learn everything about Umbraco
Get Parent Node(s) in Custom DataType Options
ProNotion
Posted: Tuesday, March 31, 2009 12:28:13 PM

Rank: Devotee

Joined: 4/22/2008
Posts: 80
Location: Plymouth, UK
I have a custom datatype using umbraco user control wrapper which is used in both front and back end. In the backend I need to walk up the tree to find the closest node that has a specific property set and set that as the selected item in my datatype - any ideas?

I understand I can use umbraco.library.GetXmlNodeById(Request.QueryString["id"]) to get the current node but not sure where to go from here?

Any help would be appreciated.

Thanks, Simon
tim
Posted: Tuesday, March 31, 2009 12:35:09 PM

Rank: Umbracoholic

Joined: 2/19/2007
Posts: 1,056
Location: Belgium
I suggest you use

umbraco.cms.businesslogic.web.Document

Fetch the current

umbraco.cms.businesslogic.web.Document current = new umbraco.cms.businesslogic.web.Document((int)Request.QueryString["id"]);

and then use a while loop to look for the closest node with the specific property set

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Tuesday, March 31, 2009 12:37:17 PM

Rank: Umbracoholic

Joined: 2/19/2007
Posts: 1,056
Location: Belgium
loop will look something like

umbraco.cms.businesslogic.web.Document parent = current.parent;

while(parent.getProperty("propertyalias").value == null)
{
parent = parent.parent;
}

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
pgnz
Posted: Tuesday, March 31, 2009 12:38:11 PM

Rank: Newbie

Joined: 8/6/2006
Posts: 23
Location: Auckland New Zealand
Tim beat me to it. I was going to say use umbraco.cms.businesslogic.Content and use the parent property on that. But Document Inherits from Content so its the same thing really.

Level 2 Certified Umbraco Developer
ProNotion
Posted: Tuesday, March 31, 2009 1:18:24 PM

Rank: Devotee

Joined: 4/22/2008
Posts: 80
Location: Plymouth, UK
Tim, thanks for the pointer which has got me to a working solution.

Code:
Document currentDoc = new Document(Convert.ToInt32(Request.QueryString["id"]));

while (currentDoc.getProperty("Branch") == null)
{
    currentDoc = new Document(currentDoc.Parent.Id);
}


currentDoc.Parent returns a CMSNode and not another document so my question now is how efficient is the above workaround and is there a better way of achieving the same?
pgnz
Posted: Tuesday, March 31, 2009 1:57:59 PM

Rank: Newbie

Joined: 8/6/2006
Posts: 23
Location: Auckland New Zealand
From my little play around there doesnt seem to be a efficient way other than creating a new document from the CMSNode.Id.

Level 2 Certified Umbraco Developer
ProNotion
Posted: Tuesday, March 31, 2009 3:41:12 PM

Rank: Devotee

Joined: 4/22/2008
Posts: 80
Location: Plymouth, UK
Thanks for looking Peter

The forum has moved

This forum is no longer in use, so you can't reply to this message - please go to Our Umbraco

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.