Add New Field to Every Content Type or Base Content Type

  • Add New Field to Every Content Type or Base Content Type spevilgenius

    In our quest to handle some requirements to levelize the type of data users are adding to Sharepoint, we have come up with the idea that we need to add a choice field to all existing content types to categorize each item/document/discussion as to the level of data it contains at the item level. This should ensure that when a user creates a new custom list or new task etc this field will be required at first but could be turned off if needed. I was hoping that this could be done using a feature but a I am unable to determine what approach to take. Can the field be created programmatically and then somehow be added to all the content types or even the base content type. It seems that if you can add it to the 0x base content type it should work. Can this be done?

  • Why not create the field declaratively using a feature and then use the OM to add the field to your base content type? This is the approach I use often and it works fine.

    Without having any code in front of me the general approach (this doesn't even rate as pseudo code!) would be:

    1. Create a feature to deploy the custom field
    2. On the feature activation you can run all your code to manipulate the base content type. I prefer not to manipulate system content types but that's just me and in your case I think you will need to.
    3. Get the base content type (0x) and custom field in question from the root SPWeb
    4. Add the field to the content type and update it. Remember to push the changes to all inheriting content types (everything in your case) by including the true flag when calling update.

    The updated MSDN documentation on SPContentType has a good example of adding a field to a content type which is pretty similar to the code you will need. I think the code hasn't changed from 2007/WSS to 2010.

    A couple of other questions...

    1. How many site collections will you need to do this to? You will need to activate this feature on every site collection that requires this functionality.
    2. You could consider building a feature stapler for your custom feature (assuming you use one) if you need to ensure all future sites will include this custom field/content type association.

wss-3.0 content-type
Related questions and answers
  • I have a few Content Types that inherit from a base Content Type. These are all wrapped up as part of my solution. I wondered, as it is possible to add additional columns to a child Content Type using FieldRefs, is it possible to remove a column for the child Content Type that is specified in the parent Content Type? It can be done on the front-end but I wondered if I could do it as part of my deployment?

  • can see that the content type should be loading it, but it does not. The other one as I said laods and works correctly. ...This is mainly a verification question as I have been fighting with an issue for a couple of days now. I have two lists derived from 2 custom content types. Both content types used the task base content type. Each of the derived content types have custom form rendering templates. I am using a custom usercontrol with codebehind added to the .ascx page as a control to redraw the forms differently

  • Organizer you have to assign rules that depend on a specific content type. So in our case we have to create identical rules for different Content Types, for example if Content Type = Contract and File Plan... content type (in our case document) that would apply to all inheriting Content Types but that is not the case. Does anyone know of a potential solution to this issue? It seems like the Content Type...We are currently doing a POC for a client to use SharePoint 2010 for Records Managment. The client has around 200 content types, and a deep nested file plan of around 500 potential nodes. In order

  • . Scoped to Site. Registration: contains a ListTemplate and a ListInstance that just modifies a basic Custom List to enable content types and add my custom content type. Scoped to Web. Here's what's happening. When I activate ContentTypes, the content type and field are deployed as expected into my site collection. When I activate Registration, the list is provisioned and the content type is added as expected. When I try to add a new item to the list, the list form only shows the Title field from Item. Now, here's the weird part. If I add a second content type to the list (through the UI

  • to the target list and then return the newly added item's "ID;#Value" pair. My Field is working fine if I add it in any list where "Folder" is not a default content type. For example, I can create..., a new item added to the lookup list, as expected, but the content type of new item is always "Folder" instead of normal "Item". I have tested my field with different types of list but there is no issue with anyone of them except "Discussion Board" list. I don't know why new item automatically becomes "Folder" in Target List, if field is used in "Discussion Board". Can anybody help? It is very

  • ); Update: I've built a C# console app which creates all lists / lookup columns / content types and add the lookup column to corresponding content type. Result: same thing, same magic number 13. Anyone...So I did create on an SPWeb 20 custom lists and then a tasks list. For each of those 20 lists I've created 20 site lookup columns. I then created 20 Content Types based on Task content type... = list; SPQuery query = new SPQuery(view); System.Text.StringBuilder sbViewFields = new System.Text.StringBuilder(); // all fields from view foreach (string field in view.ViewFields

  • hub. So I tried creating a new MMS with the old database, and entering the new URL to the content type hub, forcing the hub and subscriber jobs, all to no avail. Apart from trashing my source Content...Recently one of our SharePoint 2010 development servers died (OS related we think). I managed to get into the file system and grab all the SP databases (mdf's and ldf's). I rebuilt a new SP2010... database. No dramas there. I could browse the sites and all content looked to be intact. I then went into the connections property of the Manage Metadata services and changed the database name from

  • I recently authored a C# based script for a blog posting, which copies column data from one file to another. While testing this solution I noticed that copying this data works differently depending on the file format, which is painful to say the least. For 'non Office 2007' files I can just assign the source file's Properties variable to the destination file. For Office 2007 files I need to write the destination file, iterate through all fields of the source file and then update the destination file again. If I treat all documents the same then either meta data is not copied over

  • I can create a CQWP for the Announcement content type, but when I export the .webpart and add <property name="CommonViewFields" type="string">Expires,Date;Body,text</property> In my ItemStyles.xsl I have added this to show all the returned fields <xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle"> <xsl:for-each select="@*"> <br... not. What should I be looking for? What could I have customized? Our admin does not yet have the latest service pack installed, nor do I get much of anything out of them support wise.

Data information