none
Content Types and Inheritance RRS feed

  • Question

  • Well, I'm a bit of a deep confusion here about Content Types and inheritance.

    What I'm trying to do is to create a special contacts list. So intuitively I made a content type and inherited from SP base Contact content type. Now I got a lot of fields that I don't want in my forms.

    • I added RemoveFieldRef to the content type.. No luck All fields are there
    • I added RemoveFieldRef to the schema.xml of the list.. Same thing
    • I set Inherits attribute of the content type to False now the forms comes up empty with no fields in the content type!

    My questions -May seem naive! Sorry!-

    1. What are the benefits of inheriting from Base content types like Contact, Issue, or Task? I mean, what benefit do I get over inheriting from the generic List Item and adding my own fields?
    2. From another post here I thought that the definition of the Content Type is copied to the schema.xml, while by experiment When I set Inherits attribute of the Content Type -either at the site level or at the List level- to False. The Content Type becomes empty!
    3. To the simplest question. How to Inherit from a ContentType like Contact while having control on what fields to appear/not appear, Validation, Overwriting columns with my own?
    Thank you
    Wednesday, November 17, 2010 11:06 AM

Answers

  • Yep!

    The problem solved by deleting the debug folder in each of Obj and pkobj and bin folders under the project's folder, AND closing visual studio and reopening it. How did that solve anything I have no idea.

    As for the drama of content types inheritance/copying issue here are 3 articles from MSDN that may shade a light on this matter

    http://msdn.microsoft.com/en-us/library/ms460224.aspx

    http://msdn.microsoft.com/en-us/library/ms463016.aspx

    http://msdn.microsoft.com/en-us/library/aa543576.aspx

     

    Boy! My head hurts...

    Wednesday, November 17, 2010 1:46 PM

All replies

  • 1. you can "reuse" the base content type features (like synchronisation in Outlook for example). You can also use it for queries (for example in content by query web part). You can choose to filter only on a specific content type or to include the child content types also in the results.  

    2. Inherits attribute? What attribute are you talking about? To create content type inheriting, you only need to set the correct content type ID (in the form parent content type ID + GUID). Either ways, you content type should at least inherit from "Item" standard content type.

    It will get copied to the schema.xml when your list is instanciated but you only need to care about the list referencing the good site content type then SP will take care of the rest.

    3. This should work (remove field refs for example). Could you post the example you built, I believe there is a glitch. Overwriting columns ... you chould not do that ... and you cannot do that. Just create the column you want and add it to the content type, then removefiledref the standard columns you wish to replace. *

    PS: how did you create the content type? with Visual Studio? if so how? (create the content type, deploy and test it, then create a list from content type and choose your content type, it should work OK).


    Florin DUCA Logica Business Consulting, France
    Wednesday, November 17, 2010 11:27 AM
  • Well, thank you for your prompt reply

    1. Well, I thought there could be workflow or other features associated with each base content type. Could you point me where I could get more details. For example I'm making an EMR, and I'm making a list for hospital beds. What's the difference between inheriting from ListItem or inheriting from Resource content type?
    2. I actually use Visual Studio 2010 to generate the initial CAML code for me. Once I create a content type inherited from Contact here is the code:
      <?xml version="1.0" encoding="utf-8"?>
      <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
       <!-- Parent ContentType: Contact (0x0106) -->
       <ContentType ID="0x0106005701d0d6ffe44f99853fe1c75b3f0148"
              Name="CTSDef - Patient"
              Group="Custom Content Types"
              Description="My Content Type"
              Inherits="TRUE"
              Version="0">
        <FieldRefs>
        </FieldRefs>
       </ContentType>
      </Elements>
      Notice the Inherits="TRUE" attribute of the content type?
    3. For RemoveFieldRef it doesn't work unless I set this attribute to False. An example in my case is that I want the contact list to have 4 names for the patient instead of first and last only and to set the FullName column to a calculated field concatenating all the four names. I think I shouldn't just repeat the columns with different names. I should overwrite the FullName column with one of my own containing the formula?
    I have long experience in programming but now I feel like I'm back to the drawing board putting two by two!!!
    Wednesday, November 17, 2010 11:56 AM
  • If you could a long experience in programming you really should consider stoping to use those templates from Visual Studio, as it's more flexible. Here is some code which you can activate inside a Feature EventReceiver if the scope is set to "Site".

    SPSite currentSite = (SPSite)properties.Feature.Parent;
    
    SPWeb currentWeb = currentSite.RootWeb;
    
    SPContentType myCt = new SPContentType(currentWeb.AvailableContentTypes[SPBuiltInContentTypeId.Item], currentWeb.ContentTypes, "My Contenttype");
    
    myCt = currentWeb.ContentTypes.Add(myCt);
    

    Now you can add, remove or even hide fields via code. Hope this helps

    Wednesday, November 17, 2010 12:30 PM
  • I always considered the code approach, but isn't markup definition the recommended method from Microsoft? Almost everything in SP is supposed to be translated one way or another to CAML.

     

    Besides, I really want to understand the hierarchy of this inheritance. From more reading it looks like the List Content Type is Inherited from the Site Content Type that you create! I'm I right?

    Wednesday, November 17, 2010 12:48 PM
  • The important thing about content types is the ID. Even if you create empty content types you should create them using XML so that you can set the ID. Then you can enrich them using code. For example lookup fields should always be created using code.

    yes, the list content type inherits from the site content type ... but it's not the regular inheritance ... it's more of a special "link".


    Florin DUCA Logica Business Consulting, France
    Wednesday, November 17, 2010 1:11 PM
  • It's this special link that's driving me crazy!!

    From MSDN:

    "When you do add a site content type to a list, SharePoint Foundation makes a local copy of the site content type and adds the copy to the list. This local instance is called a list content type and applies only to the list onto which it was copied."

     

    So it's copied!! Yet when I do changes in the Site content type it's reflected in the list -but not the other way around-?? I'm testing and reading to gain more understanding of this relation. But I'm sure there is a bug in this area in Visual Studio. Some changes don't reflect when I deploy the solution which caused me more confusion. For example I currently see a column in the list content type that I've deleted from both the list content type and the site too?? Is there some sort of caching here?

    Also the Required attribute didn't work except with TRUE all caps!

    Anyway thank you for your time and effort. Any more guidance will be highly appreciated

    Regards

    Wednesday, November 17, 2010 1:22 PM
  • Yep!

    The problem solved by deleting the debug folder in each of Obj and pkobj and bin folders under the project's folder, AND closing visual studio and reopening it. How did that solve anything I have no idea.

    As for the drama of content types inheritance/copying issue here are 3 articles from MSDN that may shade a light on this matter

    http://msdn.microsoft.com/en-us/library/ms460224.aspx

    http://msdn.microsoft.com/en-us/library/ms463016.aspx

    http://msdn.microsoft.com/en-us/library/aa543576.aspx

     

    Boy! My head hurts...

    Wednesday, November 17, 2010 1:46 PM
  • Here is another article that might help:

    http://msdn.microsoft.com/en-us/library/ce8f6c58-a488-4eb0-a5fb-941e97b2bd92

    The article discusses the Inherits attribute, which is new in SP 2010. Here is what it says:

    Optional Boolean. The value of this attribute determines whether the content type inherits fields from its parent content type when it is created.

    If Inherits is TRUE, the child content type inherits all fields that are in the parent, including fields that users have added.

    If Inherits is FALSE or absent and the parent content type is a built-in type, the child content type inherits only the fields that were in the parent content type when SharePoint Foundation was installed. The child content type does not have any fields that users have added to the parent content type.

    If Inherits is FALSE or absent and the parent content type was provisioned by a sandboxed solution, the child does not inherit any fields from the parent.

    Friday, November 19, 2010 6:33 PM