Understanding Site Columns

You saw earlier that SharePoint stores data in the form of rows and columns. Columns define the schema of the data to be stored. You can have two types of columns—site columns and list columns. List columns are scoped to a list and cannot be reused in other lists. Site columns are reusable across multiple lists across multiple SharePoint sites.

SharePoint 2010 comes with a lot of out of the box site columns. In the previous section you saw the Title column in the MyCustomList list. This is an out of the box column that is present in all types of lists and libraries. To view the site columns in your SharePoint site go to Site Actions, Site Settings. Under Galleries click Site Columns link. You see the screen shown in Figure 10.1. Here you see the list of the site columns grouped under various categories. You can also see the type of the column and the source. The source indicates the site at which the column is created. It is important to note that the column is available in the source site and in all sites under the source site. If you create a new subsite and create a site column at the subsite level then the source will be shown as that subsite. In this case the column is available in the subsite and all sites under it, but is not available to the parent site.

Image

Figure 10.1. Site Columns gallery

You now create a new site column. To create a new site column follow these steps.

Go back to the list settings for the SimpleList list. Under the columns section, click the Additional Comments column. Change the name to Additional Comments 1. Click OK and try to add a new record to verify the change has reflected. Now go back to the site columns gallery. You can see that the original Additional Comments column is still there. This is an important concept to understand. When you used the Additional Comments column in the list a list column that is a copy of the site column is created. If you make any changes to the column properties from the list settings these will be local to the list column. However, if you make changes to the site column properties these get reflected to the list. The site column you created was of the Multiple Lines of Text type. You can create many other different types of site columns as described in Table 10.2.

Table 10.2. Site Column Types in SharePoint

Image

Creating a Site Column Through Features

You created the site column in the previous section using the user interface provided by SharePoint. This is useful when you are doing minor configurations to your SharePoint application. However in most cases you want to create site columns through features.

Create a new SharePoint empty project named CustomSchema. Add a new module and call it CustomColumns. Delete the sample.txt file. Edit the elements.xml as follows:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field Type="Note"
DisplayName="Additional Comments 2"
Required="FALSE"
EnforceUniqueValues="FALSE"
NumLines="8"
RichText="TRUE"
RichTextMode="FullHtml"
Group="Custom Columns"
ID="{B0980FC7-E50A-4615-BFBD-70EBB71DFE2D}"
StaticName="AdditionalComments2"
Name="AdditionalComments2" />
</Elements>

Edit the feature and name it CustomSchema. Change the scope to Site and deploy the solution. Go to the Site columns gallery and you should see your new site column there. The Field element is used to define a new site column. Table 10.3 describes some of the important attributes used previously.

Table 10.3. Attributes in the Field Element for Creating a New Site Column

Image

You can find the various types of fields you can create and a detailed description of most of these attributes at http://msdn.microsoft.com/en-us/library/ms437580.aspx.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset