SharePoint Internals – Hristo Pavlov’s Blog

12 May, 2008

Defining Custom Properies of SharePoint Fields

Filed under: SharePoint — Tags: , , — hristopavlov @ 12:17 am

One good thing about the fields schema xml is that SharePoint will not complain if you define your own attributes … well almost not complain.

So this means you can extend the fields definition and add your own properties of the fields which gives a great power to your SharePoint solutions.

 

      <Field ID={b3cae114-0197-4599-96de-c21aa709c25f}

            Type=Text

            Group=My Solution Group

            Name=BusinessUnitName

            DisplayName=Business Unit Name

            StaticName=BusinessUnitName”

            ShowInEditForm=FALSE

            ShowInNewForm=FALSE

            Hidden=FALSE

            Required=FALSE

            Sealed=FALSE

            my:MyCustomValue1=FALSE

            my:MyCustomValue2=value/>

 

The only important bit is to use a custom namespace prefix for your custom attributes as if you don’t do so your feature will fail the schema validation when you try to activate it. So simply define your namespace in the Elements element.

<Elements

xmlns=http://schemas.microsoft.com/sharepoint/ xmlns:my=http://schemas.mycompany.com/sharepoint/my/>

 

And finally to read the values of the custom attributes of your fields you will have to go via the SPField.SchemaXml property, parse the XML and read the value.

I will leave it to your imagination to think about all the powerful things you can implement by extending your field attributes.

2 Comments »

  1. [...] Defining Custom Properies of SharePoint Fields [...]

    Pingback by Links (5/19/2008) « Steve Pietrek - Everything SharePoint — 20 May, 2008 @ 12:17 am

  2. You can use GetProperty method to get property value. I use following code for this:
    protected String GetPropertyFromXml(string name)
    {
    return GetProperty(“my” + name) ?? GetProperty(name);
    }
    because namespace prefix does not exist in several cases

    Comment by Alex Lazovsky — 24 September, 2008 @ 11:57 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.