A content type is a reusable collection of settings that can be defined and applied to data in a Microsoft SharePoint list or library. Microsoft Visual Studio 2010 provides project types that support the creation and deployment of content types.
This SharePoint Visual How To walks you through the following high-level steps to show the process of creating and deploying a content type to a SharePoint 2010 site:
Creating a new Content Type project in Visual Studio 2010.
Editing the content type details.
Adding a new field to the XML markup.
Including a reference to the new field from within the content type element.
You will create a content type definition named Official Documents that is based on the Document content type. Then, you will add a choice column for Review Status, and deploy and use this content type.
To create a SharePoint 2010 content type application solution in Visual Studio 2010
Start Visual Studio 2010.
On the File menu, click New, and then click Project.
In the Installed Templates section, expand either Visual Basic or C#, expand SharePoint, and then click 2010.
In the template pane, click Content Type.
In the Name box, type OfficialDocuments.
Leave other fields with their default values, and then click OK.
In the What local site do you want to use for debugging? box, select your site.
Select the Deploy as a farm solution box. Then, click Next.
In the Choose Content Type Settings dialog box, in the Which base content type should this content type inherit from? list, select Document.
Click Finish.
To edit the content type details in the Elements.xml file
To add a field to the Elements.xml file
To deploy the project
In Solution Explorer, right-click the project, and then click Deploy.
In SharePoint, in Quick Launch, click Shared Documents.
On the Server ribbon, in the Library Tools tab group, click the Library tab.
On the ribbon, in the Settings section, click Library Settings.
In the General Settings section, click Advanced Settings.
In the Content Types section, in the Allow Management of Content Types option, click Yes.
At the bottom of the form, click OK.
On the List Information page, in the Content Types section, click Add from existing site content types.
In the Select site content types from drop-down list, click Custom Content Types.
In the Available Site Content Types list, click Official Documents, and then click Add. Then, click OK.
On the List Information page, in the Content Types section, click Change new button order and default content type.
Clear the Visible check box for the Document content type, and then click OK.
To use the new content type
In Quick Launch, click Shared Documents.
In the list of items, click Add document.
Browse to a document, click Open to upload it, and then click OK.
In the dialog box, note the Review Status drop-down list that is associated with the Official Document content type.
Save the document.
This Visual How To walks you through the following:
A content type is created by using a wizard in Visual Studio 2010.
The new content type has an ID that is formed by concatenating the parent content type identifier and a GUID that is generated by Visual Studio.
The <Field> tag is used to define a new field that will appear on a content type.
The ID of the Field should be set to a new GUID that will be unique for this field.
The Field Type is set to Choice, and then the choice options are added.
The ContentType element is then edited, so that it includes a <FieldRef> tag that specifies the new Field that has been defined by reference to the ID (GUID) of that new field. This ensures the field is included on this content type.
|
Watch the video
> [!VIDEO https://www.microsoft.com/en-us/videoplayer/embed/4d0c5966-9324-45f9-a6c0-ae3a2f9b5519]
Length: 00:04:02
Grab the code
About the Author
Ben Hedges is Senior Vice President, Research and Development at Point8020. Ben is particularly interested in modeling Talent Management, Compliance, and Learning and Development solutions on SharePoint. Ben has a wealth of experience fulfilling customer requirements by using Microsoft technologies. |