R – SharePoint Form Library: Programmatically or Stsadm command to change content type to custom form template

sharepoint

I have a custom site definition which includes a form library. I have a form template created in InfoPath. Through SharePoint features I can deploy everything except I cannot figure out how to change the default form for the form library to point to the form I created in InfoPath. I have a feature which deploys the form just great but I have to manually go into advanced settings on the form library, allow content type management, change the default content type to the template, and remove the default content type.

Any ideas on how to do this programmatically or through stsadm would be greatly appreciated!

Colby Africa

Best Answer

Here is some code I have used to do set the content types for a list.

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

Not exactly the same as your problem, but I hope it helps.

Related Topic