I don't know if there's a specific API to handle this situation, but you could do with a sql query to find all doc types that inherit from a master doc type.
var docType = new DocumentType(id);
bool hasChildren = docType.HasChildren;
If you need to get the doc types inheriting from a master use this query
select NodeId from cmsContentType where masterContentType = Id;
and use the NodeId to construct the child document type
Nope, checked the code (albeit the v4.0.2 branch) and there's no api to get the inheriting doc types (at least none that I'm aware of), but the sql would do the job.
Helpers to get the access data in umbraco api? Yes, probably, depends what you define as data (the real document data or doc types/templates etc..)?
Suggest you look into the online msdn docs available here (not really search friendly tho)
But this got me thinking, and I have an idea for you, if you're familiar with Linq2Xml.
First you need a representation of the xmldocument behind all operations in th Umbraco frontend. I noticed that several of the umbraco.library.GetXmlXXXX functions use umbraco.content.Instance.XmlContent, which returns an XmlDocument that represents the entire content as far as I can tell. But XmlDocument is only accesible with XPathNodeIterator style querying, so I made an extension method for XmlDocument that converts it to a XDocument:
using System.Xml;
using System.Xml.Linq;
namespace Iqit.UmbracoHelpers.Extensions
{
public static class XmlContentExtensions
{
public static XDocument ToXDocument(this XmlDocument xmlDocument)
{
return XDocument.Load(new XmlNodeReader(xmlDocument));
}
}
}
If you put this class in a external class library, compile it and place it in the bin folder, you should be able to query your code like so:
using umbraco;
using Iqit.UmbracoHelpers.Extensions;
protected void Page_Load(object sender, EventArgs e)
{
var doc = content.Instance.XmlContent.ToXDocument();
var nodes = from n in doc.Descendants("node")
where (string) n.Attribute("nodeTypeAlias") == "YourDocType"
select n;
}
Note that I said "should be able to" - I haven't tested this, but it compiles, and I'm pretty sure it does what you want.
DocumentType descendants
Hi,
Question - how to programmatically (C# user control) find all descendants of some Master Document Type?
Regards
AP
I don't know if there's a specific API to handle this situation, but you could do with a sql query to find all doc types that inherit from a master doc type.
If you need to get the doc types inheriting from a master use this query
and use the NodeId to construct the child document type
Hope this helps.
Regards,
/Dirk
Thanks, but what is cmsContentType? Where to find it?
AP
Ok, it is a table :) But are there any helpers to access data in Umbraco API?
AP
Nope, checked the code (albeit the v4.0.2 branch) and there's no api to get the inheriting doc types (at least none that I'm aware of), but the sql would do the job.
Helpers to get the access data in umbraco api? Yes, probably, depends what you define as data (the real document data or doc types/templates etc..)?
Suggest you look into the online msdn docs available here (not really search friendly tho)
Cheers,
/Dirk
Sounds like a task for Linq2Umbraco.
But this got me thinking, and I have an idea for you, if you're familiar with Linq2Xml.
First you need a representation of the xmldocument behind all operations in th Umbraco frontend. I noticed that several of the umbraco.library.GetXmlXXXX functions use umbraco.content.Instance.XmlContent, which returns an XmlDocument that represents the entire content as far as I can tell. But XmlDocument is only accesible with XPathNodeIterator style querying, so I made an extension method for XmlDocument that converts it to a XDocument:
If you put this class in a external class library, compile it and place it in the bin folder, you should be able to query your code like so:
Note that I said "should be able to" - I haven't tested this, but it compiles, and I'm pretty sure it does what you want.
Regards
Jesper Hauge
Well, in the end
DocumentType.GetAllAsList().Where(t => t.MasterContentType == docType.Id)
is enough for me :)
Thanks guys
is working on a reply...