locked
issue with content type definition and programming changes RRS feed

  • Question

  • Hi,

    I am having big problems with a content type definition.

    My content type inherits from the 'Page' content type. And I also added a few custom fields and I also want to remove some fields inherited from the Page CT.

    The big problems is the fields I want to remove/modify cotinue appearing in my content type and without any change.

    I tried many ways to remove the fields (Hidden = true, with the RemoveFieldRef, with the ShowInForms = true) but no way!!!

    My CT definition is using the new SP2010 'Inherits' property in the CT definition with the TRUE value. I tried to remove it or change its value to FALSE but then the CT is not deploying to the system. I know it is a weird behaviour but I know how to make it works.

    I also tried to change the display name of the 'Contact Name' file in the CT definition and also programmatically with no luck.

    This is my CT definition:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <!-- Parent ContentType: Page (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39) -->
      <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39000eb73ce2f426416b9df237093c3c2ec5"
                   Name="$Resources:abordo,ContentType_NavegacionAbordo_Nombre;"
                   Group="Desigual.Abordo3 - Custom Content Types"
                   Description="$Resources:abordo,ContentType_NavegacionAbordo_Nombre;"
                   Inherits="TRUE"
                   Version="0">
        <FieldRefs>
          <FieldRef ID="{9da97a8a-1da5-4a77-98d3-4bc10456e700}" Name="Comments" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" />
          <FieldRef ID="{aea1a4dd-0f19-417d-8721-95a1d28762ab}" Name="Contact" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" />
          <FieldRef ID="{c79dba91-e60b-400e-973d-c6d06f192720}" Name="Contact E-Mail Address" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" />
          <FieldRef ID="{dc47d55f-9bf9-494a-8d5b-e619214dd19a}" Name="Contact Picture" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInEditForm="FALSE" />

          <FieldRef ID="{7546ad0d-6c33-4501-b470-fb3003ca14ba}" Name="Contact Name" Display Name="Author" />
        </FieldRefs>
      </ContentType>
    </Elements>

     

    I tried to make the same changes programmatically with no luck. After the ct.update() the property values go back to the original values.

     

    SPContentType ctNavegacion = web.ContentTypes["Navegacion"];
    ctNavegacion.Fields[new Guid("{9da97a8a-1da5-4a77-98d3-4bc10456e700}")].Hidden = true; //Comentarios
    ctNavegacion.Fields[new Guid("{aea1a4dd-0f19-417d-8721-95a1d28762ab}")].Hidden = true; //Contacto
    ctNavegacion.Fields[new Guid("{c79dba91-e60b-400e-973d-c6d06f192720}")].Hidden = true; //Email del contacto
    ctNavegacion.Fields[new Guid("{dc47d55f-9bf9-494a-8d5b-e619214dd19a}")].Hidden = true; //Imagen del contacto
    ctNavegacion.Fields[new Guid("{7546ad0d-6c33-4501-b470-fb3003ca14ba}")].Title = ResourcesAbordo.GetResource("Field_Autor");
    ctNavegacion.Update();

     

     

    What am I doing wrong?

     

     


    • Edited by Mike Walsh FIN Wednesday, May 18, 2011 3:24 PM Big removed from Title
    Monday, May 16, 2011 1:24 PM

All replies

  • I created a custom content type inheriting from the Page Content Type.

    In the CT definition you can see I am hidding the Comments,Contact,Contact Email, and Contact Picture fields and I am also changing the display name of the Contact Name field all of them inherited from the Page content type.

     

    The problem is that after the deployment, the fields I have changed in the custom content type have not changed and remain as the original inherited ones.

     

    I tried to remove the Inherits=TRUE or setting the value to FALSE but then the content type doesn't deploy well, not appearing in the system content types list

     

    What could be the problem?

     

     

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <!-- Parent ContentType: Page (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39) -->
      <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390037748907cf314fcf8f61f03f42bdc725"
                   Name="$Resources:abordo,ContentType_Noticia_Nombre;"
                   Group="Desigual"
                   Description="$Resources:abordo,ContentType_Noticia_Nombre;"
                   Inherits="TRUE"
                   Version="0">
        <FieldRefs>
          <FieldRef ID="{9da97a8a-1da5-4a77-98d3-4bc10456e700}" Name="Comments" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInNewForm="FALSE" ShowInListSettings="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" />
          <FieldRef ID="{aea1a4dd-0f19-417d-8721-95a1d28762ab}" Name="Contact" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInNewForm="FALSE" ShowInListSettings="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" />
          <FieldRef ID="{c79dba91-e60b-400e-973d-c6d06f192720}" Name="Contact E-Mail Address" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInNewForm="FALSE" ShowInListSettings="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" />
          <FieldRef ID="{dc47d55f-9bf9-494a-8d5b-e619214dd19a}" Name="Contact Picture" Hidden="TRUE" ShowInDisplayForm="FALSE" ShowInNewForm="FALSE" ShowInListSettings="FALSE" ShowInEditForm="FALSE" ShowInFileDlg="FALSE" />
         
          <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE"/>
          <FieldRef ID="{7546ad0d-6c33-4501-b470-fb3003ca14ba}" DisplayName="$Resources:abordo,Field_AutorNoticia;" />
          <FieldRef ID="{71316cea-40a0-49f3-8659-f0cefdbdbd4f}" Name="Article Date" Required="TRUE"/>
          <FieldRef ID="{51d39414-03dc-4bd0-b777-d3e20cb350f7}" Name="Scheduling Start Date" />
          <FieldRef ID="{a990e64f-faa3-49c1-aafa-885fda79de62}" Name="Scheduling End Date" />
          <FieldRef ID="{D02A5279-0803-4161-91D3-0A1B960AD894}" Name="DestacadoNoticia" />
          <FieldRef ID="{D80BDB7C-EEFD-4601-9D8E-2C6A5A209FC1}" Name="EntradillaNoticia" />
          <FieldRef ID="{f55c4d88-1f2e-4ad9-aaa8-819af4ee7ee8}" Name="Page Content" />

          <FieldRef ID="{D5FD3234-8B51-4620-970C-D79D8A3F4DD7}" Name="VisualizacionNoticia" />
          <FieldRef ID="{2AC84FDE-9AE0-448B-A5BC-2C48E870B86C}" Name="PosibleVotacion"  Required="TRUE"/>
          <FieldRef ID="{EA80330C-4CC0-433B-A683-54CFE98DF5D5}" Name="PosibleComentarios"  Required="TRUE"/>
          <FieldRef ID="{543bc2cf-1f30-488e-8f25-6fe3b689d9ac}" Name="Rollup Image" />

          <FieldRef ID="{61cbb965-1e04-4273-b658-eedaa662f48d}" Name="Target Audiences" Hidden="TRUE"/>     
        </FieldRefs>
      </ContentType>

      <Field SourceID="http://schemas.microsoft.com/sharepoint/v3"
            ID="{D80BDB7C-EEFD-4601-9D8E-2C6A5A209FC1}"
            Name="EntradillaNoticia"
            DisplayName="$Resources:abordo,Field_EntradillaNoticia;"
            Group="Columnas Desigual"
            Type="Text" />

      <Field SourceID="http://schemas.microsoft.com/sharepoint/v3"
            ID="{D02A5279-0803-4161-91D3-0A1B960AD894}"
            Name="DestacadoNoticia"
            DisplayName="$Resources:abordo,Field_DestacadoNoticia;"
            Group="Columnas Desigual"
            Type="Text" />
    </Elements>

    Friday, May 27, 2011 10:47 AM
  • Hi JosepMola,

    I think you might have approached this from a wrong angle.  Instead of inheriting your new content type from Page content type and try to remove/hide the fields that are inherited from Page content type, you might want to inherit one or two levels higher on the parent object to Parent content type where these fields are not already there.  For Page content type, has the following parentship:

    Page <-- System Page <-- Document <-- Item

    By the look of it, all the columns in the Page content type are inherited from System page content type, so you may have to go up to the Document content type level and add the fields that you wanted in your new Page content type.

    As for your approach to remove the inherited fields from the new content type, I have not tried using object model so I cannot comment on the result of it.  But it was not possible in the web UI, so my guess is object model will also throw some exception as well.

    Cheers,

    Jeff - MSFT

    Tuesday, June 28, 2011 10:09 PM
  • Hi All,

    How you remove fields that are inherited from the parent content type is by removing the field ref like in the following example

    <FieldRefs>
     <RemoveFieldRef ID="{67df98f4-9dec-48ff-a553-29bece9c5bf4}" Name="Attachments" /> <!-- Attachments -->
     <RemoveFieldRef ID="{f1e020bc-ba26-443f-bf2f-b68715017bbc}" Name="WorkflowVersion" /> <!-- WorkflowVersion -->
     <RemoveFieldRef ID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}" Name="LinkTitleNoMenu" /> <!-- LinkTitleNoMenu -->
     <RemoveFieldRef ID="{82642ec8-ef9b-478f-acf9-31f7d45fbc31}" Name="LinkTitle" /> <!-- LinkTitle -->
     <RemoveFieldRef ID="{ae069f25-3ac2-4256-b9c3-15dbc15da0e0}" Name="GUID" /> <!-- GUID -->
     <RemoveFieldRef ID="{de8beacf-5505-47cd-80a6-aa44e7ffe2f4}" Name="WorkflowInstanceID" /> <!-- WorkflowInstanceID -->
    </FieldRefs>
    

     

    There are some additional gotchas to upgrading existing content types in SP2007. you cant use declarative xml to make changes to content typoes once they are deployed. youcan programatically make changes to content types. Also, if yuou modify the columns directly ion a library whe=re the Content typoes ahve been deployed you can break the inhritance or in other words the ability to push down changes from the content type. If making changes through the gui make sure you make the changes to the cotent type and let the changes propagate down to the lists or libraries.

     

    -Ivan

     

     

     


    Ivan Sanders My LinkedIn Profile, My Blog, @iasanders.
    Wednesday, June 29, 2011 7:24 AM
  • Hi,

     

    I've already used the solution proposed by Ivan, using the RemoveFieldRef tag, but with no luck.

    About the Jeff solution, it's more or less what I've finally done. Using the System Page, instead the Page content type as the parent CT and adding all the remaining fields I wanted. I also added some code to modify the content type used in the library hidding the fields I didn't want.

                pagesList.Fields[ConstValues.FieldsNoticias.Comments].Hidden = true;
                pagesList.Fields[ConstValues.FieldsNoticias.Comments].Update(true);

    This was the only solution that worked. Modifying the custom content type that is on the content type galleries in order to hide some fields didn't worked. I had to modify the content type used in the library/list that is inheriting from the custom content type.

     

    Wednesday, June 29, 2011 9:15 AM
  • Hi, 

     

    It's been a long time but for the next, just take a look at ContentType attributes. Add <ContentType.... overwrite="TRUE" ...>. The changes for inherits fieldref must be overwrite now.

     

    Jc


    • Edited by JcBrabant Tuesday, September 6, 2011 11:19 AM error
    Tuesday, September 6, 2011 7:05 AM
  • With the help of RemoveFieldRef tag, you can remove the fields. For example:
    
      <ContentType ID=""
              Name="Amit Kumar Content Type"
              Description="ContentType for Amit Kumar"
              Group="Amit Content Types"
              Version="0">
        <FieldRefs>
          <FieldRef ID="{11856B76-30A7-467B-B2B2-9713E798272A}" Name="Description" Required="TRUE" />
          <RemoveFieldRef ID="{aea1a4dd-0f19-417d-8721-95a1d28762ab}" />
          <RemoveFieldRef ID="{246D0907-637C-46b7-9AA0-0BB914DAA832}" />
          <RemoveFieldRef ID="{543bc2cf-1f30-488e-8f25-6fe3b689d9ac}" />
        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
              <Edit>CustomForm</Edit>
              <New>CustomForm</New>
            </FormTemplates>
          </XmlDocument>
        </XmlDocuments>
      </ContentType>  
    
    


    Thanks, Amit Kumar, LinkedIn Profile ** My Blog
    Tuesday, September 6, 2011 9:48 AM