Adding content type programatically
Scenario:
You want to add Content Type programatically
Solution:
SharePoint Object Model
Code:
You want to add Content Type programatically
Solution:
SharePoint Object Model
Code:
- using (SPSite site = new SPSite("http://localhost")) {
- using (SPWeb web = site.OpenWeb()) {
- SPContentType baseType = web.AvailableContentTypes["Document"];
- SPContentType proposal = new SPContentType( baseType, web.ContentTypes, "Project Proposal");
- proposal.FieldLinks.Add(new SPFieldLink(web.AvailableFields["Author"]));
- web.ContentTypes.Add(proposal);
- }
- }
Comments
Post a Comment