SharePoint: LINQ query to get child content types
I had been putting off using / learning linq for a little while, but am now finally writing some .net 3.5 code for sharepoint where there are some clear uses for it. I am finding it really intuitive.
Anyway, below is one of my first real-world linq queries - it is a simple query to get all of the descendant content types from a given content type (note that the parent content type is also included):
SPContentTypeId parentId = new SPContentTypeId("parentContentTypeId");
using (SPSite mySiteCollect= new SPSite("http://url/to/my/spweb"))
{
using (SPWeb website = siteCol.OpenWeb())
{
IEnumerable<SPContentType> descendantContentTypes =
from SPContentType childCt in myspweb.AvailableContentTypes
where childCt.Id.IsChildOf(parentId)
select childCt;
// Do something here with descendant content types
}
}
post a comment / view comments (currently 0 comments)
- Bookmark with:
- Delicious
- Digg
- StumbleUpon