2

How to add the managed metadata field to a custom page layout ? This need to done through visual studio. Any thoughts ?

EDIT

These are the steps I have done so far. I'm doing it in VS and deploying the same to SP Server.

  1. Added a layout column (site column) like this.
> <Field Type="TaxonomyFieldType" DisplayName="Contextual Help Contexts
> New" Required="FALSE" ID="{F2189C6B-910D-45AA-9FD8-E5B9DBC7AC1A}"
> Name="ContextualHelpContextsNew"
> StaticName="ContextualHelpContextsNew" Group="SPDP Columns" />
  1. Added this new field in the ContentType.
> <FieldRef ID="{F2189C6B-910D-45AA-9FD8-E5B9DBC7AC1A}"
> Name="ContextualHelpContextsNew" />
  1. Referenced the field in PageLayout like this.
>        <div id="PageContentMain">     
>             <PublishingWebControls:RichHtmlField FieldName="PageContentMain"
> runat="server"></PublishingWebControls:RichHtmlField>
>             <Taxonomy:TaxonomyFieldControl FieldName="ContextualHelpContextsNew" InputFieldLabel="Help Contexts"
> runat="server"></Taxonomy:TaxonomyFieldControl>
>         </div>

Whats going wrong ?

7
  • 1
    First step add a managed metadata column, its related notes field and the two TaxCatch fields to the related content type of the page layout. Then just add a TaxonomyFieldControl to the page layout Commented Feb 23, 2014 at 8:57
  • I have updated the question. Please suggest what all changes needed. I'm totally new to the technology. Thanks for your help.
    – Anish V
    Commented Feb 23, 2014 at 9:20
  • Here is a better way of provisioning the field wictorwilen.se/Post/…, less based on XML Commented Feb 23, 2014 at 9:26
  • I cannot use a server side code. Currently we are keeping the layouts, contenttypes etc as an xml file in VS. While deploying these will we hosted in the server. Hence, I want the changes in xml file.
    – Anish V
    Commented Feb 23, 2014 at 10:44
  • Then you will have to provision the notes field that will be bound to the taxonomy field as well as add the two TaxCatch fields to the content type xml. You will also have to make sure that the new content type changes gets pushed out to all libraries Commented Feb 23, 2014 at 11:14

2 Answers 2

2

Have you registered the Taxonomy control assembly/namespace in your page layout?

You should have something such as the following in top of your layout page:

<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

2

What I suggest is,

Create Site Columns as follows

<Field
    ID="{7A2608F0-A2AC-435D-8011-A8E640AB091F}"
    Name="ABCCode"
    DisplayName="ABC Code"
    Type="TaxonomyFieldType"
    Group="Custom Site Columns"
    Description="To display ABC Codes"
    ShowField="Term1033"
    Required="FALSE"
    EnforceUniqueValues="FALSE">
    <Customization>
      <ArrayOfProperty>
        <Property>
          <Name>TextField</Name>
          <Value xmlns:q6="http://www.w3.org/2001/XMLSchema" p4:type="q6:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">
            {2169B2F2-43E4-460A-9999-84094F0A0A30}
          </Value>
        </Property>
      </ArrayOfProperty>
    </Customization>
  </Field>
  <Field
      ID="{2169B2F2-43E4-460A-9999-84094F0A0A30}"
      Name="ABCCodeText"
      DisplayName="ABC Code Text"
      Type="Note"
      Group="Custom Site Columns"
      Hidden="TRUE"
      Required="FALSE"
      ShowInNewForm="FALSE" />

Associate the Taxonomy and Note fields using server side code in some feature activation event.

Guid fieldIdTextField = new Guid("{2169B2F2-43E4-460A-9999-84094F0A0A30}");

Taxonomyfield.TextField = fieldIdTextField ;

Taxonomyfield.Update();

Add the site column to CType

<ContentType ID="0x0100B83402A1721B4A3099A8AC91E3A7E6C4" 
               Name="SomeRequest" 
               Group="Custom Content Types" 
               Description="This content type will have a list of site columns required to create a quote request." 
               Inherits="TRUE" 
               Version="0">
    <FieldRefs>
      <FieldRef ID="{2CB503A2-0FCB-465A-9BD9-31D60D12A21A}" DisplayName="ABC" Required="FALSE" Description="To display ABC Codes" Name="ABC" />
    </FieldRefs>
  </ContentType>

Add the CType to PageLayout in its Elements.xml file

<File Path="PageLayouts\PageLayout.aspx" Url="PageLayout.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE"  Level="Published" ReplaceContent="true">
      <Property Name="Title" Value="PageLayout Title"></Property>
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;"></Property>
      <Property Name="FeatureId" Value="$SharePoint.Feature.Id$" Type="string"/>
      <Property Name="PublishingAssociatedContentType" Value=";#CType;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900A22F433C8ABF4216B2F384B38BF6F2C7;#" />
    </File>

Open the Pagelayout in SharePoint designer and show the toolbox which will show the fields from your associated content type of the pagelayout. Just drag and drop the field which will create the mark up for you and it adds the register tag also at the top of the page. You don't really need to type anything manually which is vulnerable.

Let me know if you have any questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.