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?
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.
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);
}[/code]
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?
Get Parent Node(s) in Custom DataType
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
Comment author was deleted
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
Comment author was deleted
loop will look something like
umbraco.cms.businesslogic.web.Document parent = current.parent;
while(parent.getProperty("propertyalias").value == null)
{
parent = parent.parent;
}
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.
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);
}[/code]
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?
From my little play around there doesnt seem to be a efficient way other than creating a new document from the CMSNode.Id.
Thanks for looking Peter
Hello
Is Simons solution still the prefered way of doing this?
is working on a reply...