Create custom Columns & Content Types in SharePoint 2007 (MOSS) using C# |
Jul
26
|
« How to change the listening port for RDC/RDP (Remote Desktop Connection) | How to Change an Office 2010 License/Product Key » |
I created a small utility using C# to do the following in tasks (listed below) in SharePoint. The example code used for this is also located in this article it covers all of these SharePoint tasks.
1. Create 3 columns in SharePoint.
a. “Example Amount” – Type: Current, Not a Required Field
b. “Example Date” – Type: Date and Time, Not a Required Field
c. “Example Choice” – Type: Choice Field, Not a Required Field
d. Add these three columns to a group named “_Example Column Group”
2. Create “Content Type 1”
a. Create “Content Type 1”
b. Add “Example Amount” to this Content Type
c. Add “Example Date” to this Content Type, sets the field to Required within the Content Type
d. Add this content type to a group named “_Example Content Type Group”
3. Create “Content Type 2”
a. Create “Content Type 2”
b. Make this a child of “Content Type 1”
c. Add “Example Choice” to this Content Type, renames the column to “ExampleChoices” & sets the field to Required within the Content Type
d. Add this content type to a group named “_Example Content Type Group”
This is how the utility looks, I enter the URL and it runs all of the tasks listed above. Before we get into the code let’s take a look at the results
We can see that three Site Columns were created. I use an underscore in the beginning of the group name so it will come up first in the Site Column Gallery
We can see that two Site Content Types were created and Content Type 2 is a child of Content Type one. We also can notice that “Content Type 1” parent is “Document” Content Type. Now let’s examine the Content Types
We notice the two Site Columns that were added to “Content Type 1” and that we changed the “Example Date” column to “Required” within “Content Type 1”
We notice that “ExampleChoices” was added to “Content Type 2” and it was set to a “Required” column. We also notice that “Content Type 2” inherited the columns from “Content Type 1”
This is the SharePoint specific code that was use during the creation of this utility. You can double click to code to select it, then copy it.
|