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.

  • Using Sharepoint UI or code or feature? Commented Aug 30, 2012 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
    Commented Aug 30, 2012 at 20:22

1 Answer 1


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.

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.