13 Sep 2011

Site Columns [Field] SharePoint

 

A Site Column describes a reusable data type model that you can use in many different Content Types and lists definitions, across multiple SharePoint sites.

Example: Site Column defined in a feature element

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{A33ffs0-55CD-4d34-A015-8119342sdfCE24}"
Name="DevCompanyName"
StaticName="DevCompanyName"
DisplayName="Company Name"
Type="Text"
Group="Dev Columns" />
</Elements>

 

Name is a required attribute, and like the ID attribute, it should also be unique,

I suggest that you assign the Name and the StaticName the same value, avoid using non-alphanumeric characters, and provide a descriptive value for the DisplayName attribute.

The Type attribute is mandatory for Site Column definitions. It defines the data type assigned
to the field.

Complete list of field types: http://msdn.microsoft.com/en-us/library/ms437580(office.14).aspx

 

Common Field Types

Field Type Name

DataBase Type

Object Model

Boolean bit SPFieldBoolean
Choice nvarchar SPFieldChoice
MultiChoice ntext SPFieldMultiChoice
Currency float SPFieldCurrency
DateTime datetime SPFieldDateTime
Note ntext SPFieldMultiLineText
Text nvarchar SPFieldText
User and UserMulti ints SPFieldUser
     

 

Optional Boolean Attributes Available for the Field Element

Hidden
The Hidden attribute can assume a value of TRUE or FALSE.

ReadOnly
The field will not be displayed in New and Edit forms, but can be included in
Views.

Required

RichText

It determines whether a text field will accept rich text formatting.

ShowInDisplayForm  

ShowInEditForm

ShowInNewForm

 

Example :  MultiChoice site column defined in a feature element.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{1afdsfA1-5BBB-468d-AA35-91ACEfdsaf3B}"
Name="DevCountry"
StaticName="DevCountry"
DisplayName="Country"
Type="Choice"
Group="Dev Columns" Sortable="TRUE">
<Default>Italy</Default>
<CHOICES>
<CHOICE>Italy</CHOICE>
<CHOICE>USA</CHOICE>
<CHOICE>Germany</CHOICE>
<CHOICE>France</CHOICE>
</CHOICES>
</Field>
</Elements>

Validation Rules

The Validation element can have a Message attribute, which defines an error message to show to the end user when validation fails, and a Script attribute, which defines a JavaScript rule that performs the validation.

Calculated Fields and Formulas in SharePoint: http://msdn.microsoft.com/en-us/library/bb862071(office.14).aspx

No comments:

Post a Comment