SharePoint表单库:以编程方式或Stsadm命令将内容类型更改为自定义表单模板

时间:2009-02-11 19:59:32

标签: sharepoint

我有一个自定义网站定义,其中包含一个表单库。我有一个在InfoPath中创建的表单模板。通过SharePoint功能,我可以部署所有内容,除了我无法弄清楚如何更改表单库的默认表单以指向我在InfoPath中创建的表单。我有一个功能,可以部署表单,但我必须手动进入表单库的高级设置,允许内容类型管理,将默认内容类型更改为模板,并删除默认的内容类型。

有关如何以编程方式或通过stsadm执行此操作的任何想法将非常感谢!

非洲科尔比

1 个答案:

答案 0 :(得分:1)

以下是我用来设置列表内容类型的一些代码。

 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();
    }

与您的问题不完全相同,但我希望它有所帮助。

相关问题