這是我用來做一些代碼設置列表的內容類型。
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();
}
與您的問題不完全相同,但我希望它有幫助。
來源
2009-02-11 20:30:15
Nat
您是否使用自定義列表定義? – webwires 2009-02-11 21:10:53