IT tutorials
 
Technology
 

Sharepoint 2010 : Data Access Overview - Columns (part 1)

10/27/2013 9:22:13 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
You’ve seen how content types are used throughout SharePoint to determine how specific types of data should be handled. We’ve looked at the types of metadata that can be stored within a content type. One of the areas that we haven’t discussed so far is how individual items of data are defined, and that’s where columns come in. Every content type contains a reference to one or more column objects, where a column defines a specific data element together with any appropriate metadata required to capture, process, and render it. Columns can be reused in multiple content types, and in fact this reuse is central to the way content type inheritance is implemented. For example, suppose the Item content type references a column named Title. As a result, all content types that inherit from Item also contain a reference to this Title column.

Columns, like content types, are available across child sites. Where the columns are used in a content type that is published using content type publishing, the columns are available across site collections.

One of the most important properties of a column is the type of data that it can contain. A number of built-in options are available, and a full list can be obtained by examining the SPFieldType enumeration in the Microsoft.SharePoint namespace. Some of the commonly used types include the following:

  • Integer Specifies that the column contains an Integer value

  • Text Specifies that the column contains a single line of text

  • Note Specifies that the column contains multiple lines of text

  • Number Specifies that the column contains a floating point number

  • Lookup Specifies that the column contains a reference to a value in another list

The following code sample shows how to create columns and associate them with content types:

static void Main(string[] args)
{
string siteUrl = "http://localhost";
List<string> fieldNames = new List<string>();
Program p = new Program();

using (SPSite site = new SPSite(siteUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPContentType newContentType;
newContentType = p.CreateContentType(web,
"MyFirstContentType",
"Item");

p.CreateSiteColumn(web, "MyColumn",
SPFieldType.Text,
false);

fieldNames.Add("MyColumn");

p.CreateSiteColumn(web, "MyColumn2",
SPFieldType.Text,
false);

fieldNames.Add("MyColumn2");
p.AddFields(web, fieldNames.ToArray(), newContentType);

Console.WriteLine("{0} | {1} | {2}", "Title".PadRight(20),
"Type".PadRight(20),
"Group".PadRight(20));
Console.WriteLine(new string(′-′, 70));

foreach (SPField fld in newContentType.Fields)
{
Console.WriteLine("{0} | {1} | {2}", fld.StaticName.PadRight(20),
fld.TypeDisplayName.PadRight(20),
fld.Group.PadRight(20));
}
}
}
Console.ReadLine();
}


void CreateSiteColumn(SPWeb web, string name, SPFieldType fieldType,
bool isRequired)
{
if (!web.AvailableFields.ContainsField(name))
{
web.Fields.Add(name, fieldType, isRequired);
}
}

void AddFields(SPWeb web, string[] fieldNames, SPContentType contentType)
{
foreach (string fieldname in fieldNames)
{
if (web.Fields.ContainsField(fieldname))
{
SPFieldLink fieldLink = new SPFieldLink(web.Fields[fieldname]);
contentType.FieldLinks.Add(fieldLink);
}
}
//Update should be called to persist these changes
//contentType.Update();
}
 
Others
 
- Sharepoint 2010 : Data Access Overview - Content Types (part 3) - Enterprise Content Types
- Sharepoint 2010 : Data Access Overview - Content Types (part 2) - Content Type Metadata
- Sharepoint 2010 : Data Access Overview - Content Types (part 1) - Content Type Inheritance
- Windows 7 : Using CDs and DVDs - Using Disks that Already Contain Data (part 2) - Changing what happens when you insert a CD or DVD
- Windows 7 : Using CDs and DVDs - Using Disks that Already Contain Data (part 1)
- Windows 7 : Using CDs and DVDs - What Kind of Drive Do I Have?
- Windows 7 : Kernel Mode Installation and Build - Testing a KMDF Driver
- Windows 7 : Kernel Mode Installation and Build - Catalog Files and Digital Signature, Installing Featured Toaster
- Windows Phone 8 : Enterprise Phone Apps - Preparing Apps for Distribution, Building a Company Hub
- Windows Phone 8 : Enterprise Phone Apps - Application Enrollment Token , Registering Phones
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us