title: Get Child Content Types of a Content Type
body: <p>How can I get the child content types of a content type?</p>
  
  <p>From <a href="http://blog.thekid.me.uk/archive/2007/05/21/using-the-contenttypeid-to-query-child-content-types-in-sharepoint.aspx" rel="nofollow">here</a> I've learned that, all the child content types have the contentTypeId begins with the parent's ID. So, I tried to use the suggested way that is in the link.</p>
  
  <p>Let me show you what I've tried first:</p>
  
  <pre><code>        using (var site = new SPSite(SPContext.Current.Site.ID))
          {
              using (var web = site.RootWeb)
              {
                  SPContentTypeId ctId = new SPContentTypeId(MasterContentTypeId);
                  SPContentType masterCt = web.ContentTypes[ctId];
  
                  var queryString = string.Empty;
                  queryString += "&lt;Where&gt;";
                  queryString += "&lt;BeginsWith&gt;";
                  queryString += "&lt;FieldRef Name='ContentTypeId'/&gt;";
                  queryString += "&lt;Value Type='Text'&gt;";
                  queryString += MasterContentTypeId;
                  queryString += "&lt;/Value&gt;";
                  queryString += "&lt;/BeginsWith&gt;";
                  queryString += "&lt;/Where&gt;";
  
                  SPSiteDataQuery query = new SPSiteDataQuery { Query = queryString };
                  DataTable dt = web.GetSiteData(query);
                  DataView dv = new DataView(dt);
  
                  foreach (DataRow row in dt.Rows)
                  {
                      //Do Something Necessary
                  }
              }
          }
  </code></pre>
  
  <p>But the DataTable returns with no rows.</p>
  
  <p>Is this the right way to do this but there's something missing or wrong; or am I doing this all wrong?</p>