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.

About these ads

3 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

  3. It appears that custom properties are not valid on content type CAML. Does anyone have a solution for for content types? We are using a hidden field with custom properties, but the extra level of indirection via a field is awkward. We would prefer properties directly on the CTs. Also PropertyBag does not apply to CTs, only list, list item, file, folder, or website.

    Comment by JohnC — 7 June, 2011 @ 2:51 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: