void AddContentTypes(SPWeb web)
{
//get a reference to content types previously installed
SPContentType CompanyAContentPage = web.AvailableContentTypes["CompanyA Content Page"];
SPContentType CompanyAWelcomePage = web.AvailableContentTypes["CompanyA Welcome Page"];
//get list to mess with
SPList spList = web.Lists["Pages"];
//enable management of content types
spList.ContentTypesEnabled = true;
//get the content types added to the list (different from the web ones)
SPContentType newCompanyAPageContentType = spList.ContentTypes.Add(CompanyAContentPage);
SPContentType newCompanyAWelcomePageContentType = spList.ContentTypes.Add(CompanyAWelcomePage);
//update list
spList.Update();
//get a list of content types for the "new" drop down on the list
List<SPContentType> contentTypeList = new List<SPContentType>();
contentTypeList.Add(newCompanyAPageContentType);
contentTypeList.Add(newCompanyAWelcomePageContentType);
//set the content types for the "new" drop down list
spList.RootFolder.UniqueContentTypeOrder = contentTypeList;
spList.RootFolder.Update();
}
1 回答
以下是我用来设置列表内容类型的一些代码 .
与您的问题不完全相同,但我希望它有所帮助 .