SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to attach a custom content type to Document Library so that it's available to users whenever they upload a new document, they'll have the necessary columns visible. I'm struggling to staple this onto SharePoint 2010 and cannot really find a solution to this online.

share|improve this question
Using Sharepoint UI or code or feature? – Ashish Patel Aug 30 '12 at 19:59
Ashish, I created the content type as a feature and activated it. What I need to do now, is "attached" this custom type to document libraries created with the creation of a new site. Can I do this via the ONET, if so, how? – JadedEric Aug 30 '12 at 20:22

You can attach a contenttype to a list in a feature:

  • Get a reference to the list
  • Check if the list accepts contenttypes
  • Add the contenttype

And in code:

SPList list = web.Lists["your list"];
list.AllowContentTypes = true;
SPContentType ct = web.AvailableContentTypes["your contenttype"];

This isn't production code, please add some checks and exception handling.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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