You are here: Home » Modify the inherited properties of a field

Modify the inherited properties of a field

Posted by aghy
No Comments »

One of my colleagues found a very interesting thing in SharePoint:: It's forbidden to modify the inherited field's properties (for example AllowMultipleValues defined by SPFieldLookup class) via properties! Doing this you start a back process, and the SharePoint donesn't use the field class anymore, but the fields will be created from the root class. Why? – That's a good question. Most likely because it's not supported.

So you can modify the properties defined in the root class only with one method: through the schema. You can handle the schema vie SchemaXml, and the used Xml is depends on the ancestors of the fields. If you set the SchemaXml, the properties will be changed immediately, it's unnecessary to call Update method.

By the way, you can find the schema descriptions at http://msdn2.microsoft.com/en-us/library/ms437580.aspx.

On the OnAdded method you can modify the schema, because it's sure that here it exists. In other cases you can do this in the Update method, after calling the base.Update.

private void SetSchemaAttribute(string attributeName, string value)

{

XmlDocument doc = new XmlDocument();

doc.LoadXml(SchemaXml);

XmlNode node = doc.DocumentElement;

XmlNode namedItem = node.Attributes.GetNamedItem(attributeName);

if (namedItem == null)

{

XmlAttribute attribute = doc.CreateAttribute(attributeName);

attribute.Value = value;

node.Attributes.SetNamedItem(attribute);

}

else namedItem.Value = value;

SchemaXml = doc.OuterXml;

}

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>