Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer

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"];
list.ContentTypes.Add(ct);

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

share|improve this answer
add comment

Your Answer

 
discard

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.