[Code Update] SDK and Microsoft Press Both Wrong?? Custom Fields in the schema.xml
class
ContentTypeInstaller : SPFeatureReceiver
// CODE DESCRIPTION
// —————-
/*
public override void FeatureActivated(SPFeatureReceiverProperties properties)
using(SPSite site = (SPSite)properties.Feature.Parent)
"");
// loop through each of the elements in the feature
foreach (SPElementDefinition element in properties.Definition.GetElementDefinitions(CultureInfo.CurrentCulture))
Loop through feature elements
// retrieve the xml content for the feature element
// only continue if the element is a content type definition
if (content.Name == "ContentType")
// grab a new Content Type object
string strCTypeID = content.Attributes["ID"].Value;
new SPContentTypeId(strCTypeID)];
Get FieldRef Order from Content type
// grab the original order, we will need this later
string[] fieldOrder = new string[cType.FieldLinks.Count];
int x = 0;
foreach (SPFieldLink fieldlink in cType.FieldLinks)
Add new columns to the content type
// loop through each sub-node in the Content Type file
foreach (XmlNode node in content.ChildNodes)
loop through sub nodes
// only continue for
// the FieldRefs collection
if (node.Name == "FieldRefs")
foreach (XmlNode fieldRef in node.ChildNodes)
Loop through FieldRefs
// only apply for FieldRef tags
if (fieldRef.Name == "FieldRef")
// retrieve the SPField object
string fieldID = fieldRef.Attributes["ID"].Value;
//SPFieldLink fieldLink = cType.FieldLinks[new Guid(fieldID)];
new Guid(fieldID)];
// first we need to remove the fieldref
new Guid(fieldID));
// and save, pushing this change down
true);
// NOTE – this will NOT delete any content
// in existing lists!
// now add the field back in again
new SPFieldLink(field));
// and call an update, pushing down all changes
true);
// NOTE – this is what adds the column to those
// lists who don’t already have it.
Apply changes
// reset the field order
// it is possible that adding and
// removing fields would have
// affected this
// force update of the content type,
// pushing down to children
true);
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)