You are here: Home » SharePoint content types inheritance fixed

SharePoint content types inheritance fixed

Posted by nsevens
No Comments »

I came across a great post from Martin Hatch today, which provides a solution for problems with content types and list definitions in features.

I tested it and it seems to work great, although i did make a little change, since the handler throws an error when using a RemoveFieldRef node in the CT definition.

So, i changed this: 

foreach (XmlNode fieldRef in node.ChildNodes)

{

    #region Loop through FieldRefs

    //ignore XML comment tags

    if (fieldRef.Name == "#comment")

    {

       continue;

    }

    string fieldID = fieldRef.Attributes["ID"].Value;

    SPField field = cType.Fields[new Guid(fieldID)];

    cType.FieldLinks.Delete(new Guid(fieldID));

    cType.Update(true);

    cType.FieldLinks.Add(new SPFieldLink(field));

    cType.Update(true);

    #endregion

}

to this:

foreach (XmlNode fieldRef in node.ChildNodes)

{

    #region Loop through FieldRefs

    //ignore everything but FieldRefs

    if (fieldRef.Name == "FieldRefs")

    {

        string fieldID = fieldRef.Attributes["ID"].Value;

        SPField field = cType.Fields[new Guid(fieldID)];

        cType.FieldLinks.Delete(new Guid(fieldID));

        cType.Update(true);

        cType.FieldLinks.Add(new SPFieldLink(field));

        cType.Update(true);

    }

    #endregion

}

Seems to work to me, but if anyone has another suggestion :) please do let me know ;)

Your email is never shared.
Required fields are marked *




Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>