Thursday 30 May 2013

create a SharePoint 2010 content type application solution in Visual Studio 2010

To create a SharePoint 2010 content type application solution in Visual Studio 2010

  1. Start Visual Studio 2010.
  2. On the File menu, click New, and then click Project.
  3. In the Installed Templates section, expand either Visual Basic or C#, expand SharePoint, and then click 2010.
  4. In the template pane, click Content Type.
  5. In the Name box, type OfficialDocuments.
  6. Leave other fields with their default values, and then click OK.
  7. In the What local site do you want to use for debugging? box, select your site.
  8. Select the Deploy as a farm solution box. Then, click Next.
  9. In the Choose Content Type Settings dialog box, in the Which base content type should this content type inherit from? list, select Document.
  10. Click Finish.

To edit the content type details in the Elements.xml file

  1. In Solution Explorer, expand ContentType1 and then open Elements.xml.
  2. Edit the Name attribute in the <ContentType> tag and type Official Documents.
  3. Edit the Description attribute in the <ContentType> tag and type Official Document Content Type.
    The markup should look similar to the following.
    noteNote:
    The ContentType ID is a GUID and your ID will differ.
    <ContentType ID="0x01010055a134438a8544eaa18477c8f21894d0"
      Name="Official Documents"
      Group="Custom Content Types"
      Description="Official Document Content Type"
      Inherits="TRUE"
      Version="0">

To add a field to the Elements.xml file

  1. Above the <ContentType> tag, add the following markup. Notice that this includes a new field that will be identified with a new GUID. For this exercise, you can either use the GUID in the following code or create your own GUID.
    <Field ID="{30C3D21A-A7C9-410E-A896-82875475F697}" Name="ReviewStatus" DisplayName="Review Status" Type ="Choice" >
      <CHOICES>
        <CHOICE>Review Required</CHOICE>
        <CHOICE>Review in Progress</CHOICE>
        <CHOICE>Review Completed</CHOICE>
      </CHOICES>  
    </Field>
  2. Between the begin and end <FieldRefs> tags in the <ContentType> tag, add the following <FieldRef> tag. Ensure that the GUID matches that of the <Field> in the previous step.
    <FieldRef ID="{30C3D21A-A7C9-410E-A896-82875475F697}" 
      Name="ReviewStatus" DisplayName="Review Status"  />

To deploy the project

  1. In Solution Explorer, right-click the project, and then click Deploy.
  2. In SharePoint, in Quick Launch, click Shared Documents.
  3. On the Server ribbon, in the Library Tools tab group, click the Library tab.
  4. On the ribbon, in the Settings section, click Library Settings.
  5. In the General Settings section, click Advanced Settings.
  6. In the Content Types section, in the Allow Management of Content Types option, click Yes.
  7. At the bottom of the form, click OK.
  8. On the List Information page, in the Content Types section, click Add from existing site content types.
  9. In the Select site content types from drop-down list, click Custom Content Types.
  10. In the Available Site Content Types list, click Official Documents, and then click Add. Then, click OK.
  11. On the List Information page, in the Content Types section, click Change new button order and default content type.
  12. Clear the Visible check box for the Document content type, and then click OK.

To use the new content type

  1. In Quick Launch, click Shared Documents.
  2. In the list of items, click Add document.
  3. Browse to a document, click Open to upload it, and then click OK.
  4. In the dialog box, note the Review Status drop-down list that is associated with the Official Document content type.
  5. Save the document.
Read It
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.

No comments:

Post a Comment