locked
Trouble with Content Types deployed via a Feature

    Question

  • Has anyone else come across the same issue?

    I've just developed 14 new Content Types: all of them are Sealed, have the same five fields (title, author, subject, keywords and comments) and each has its own .docx template file.

    I added the Content Types to a Feature and deployed it to my MOSS 2007 development server. When I activate the Feature (at Site Collection level) the new Content Types show within the Site Content Type Gallery. I then added the new Content Types to a document library.

    Now, this is the bit where things seem to go wrong.

    When I create a new document within the library (by choosing a Content Type from the "New" menu) the correct Word template opens, but - according to the document properties bar within Word - its using the wrong Content Type!

    Most of the time it seems to be showing the title of the default Content Type, but never the correct title.

    Saving the new document back to the library saves it as the wrong Content Type too.

    Any ideas? I can supply my elements.xml file if its of any use.

    Many thanks in advance.

    Wednesday, April 7, 2010 4:10 PM

Answers

  • One last update...

    I now have a working Console Application and it seems that all I need to do is loop through the new Content Types and re-apply the DocumentType property.

    SPContentTypeCollection collection = web.ContentTypes;
    
    foreach (SPContentType contentType in collection)
    {
      String template = contentType.DocumentTemplate;
    
      contentType.ReadOnly = false;
      contentType.Update(true);
    
      contentType.DocumentTemplate = template;
      contentType.ReadOnly = true;
      contentType.Update(true);
    
      Console.WriteLine(String.Format("Updated '{0}'.", contentType.Name));
    }
    I'm wondering if I can attach the same functionality to the Feature and have the code run when the Feature is activated. Hope this helps someone.
    • Marked as answer by Ryan Ball Thursday, April 8, 2010 10:55 AM
    Thursday, April 8, 2010 10:54 AM

All replies

  • Following up on this issue... after lots of Web browsing, it seems I'm not the only one to come across this issue (which means I can ignore any doubts about my custom Content Types).

    As far as I can tell, there seems to be no clear solution to the issue.

    The only thing that seems to work for me is: After I've deployed my Feature and activated it at Site Collection level, I amend each Content Type via the Site Content Type Gallery and manually upload it's document template file. I also ensure that "Update all content types inheriting from this type?" is set to "Yes". If I then return to my document library and create a new Word document via the "New" menu, Word seems to remember which Content Type it is using and correctly saves the new file back to the document library.

    So, my next step is to write a Console Application to upload the document templates each time I create a new Site Collection. Not an ideal solution as the document templates were originally included within the Feature. Can anyone suggest an alternative solution?

    Thursday, April 8, 2010 9:30 AM
  • One last update...

    I now have a working Console Application and it seems that all I need to do is loop through the new Content Types and re-apply the DocumentType property.

    SPContentTypeCollection collection = web.ContentTypes;
    
    foreach (SPContentType contentType in collection)
    {
      String template = contentType.DocumentTemplate;
    
      contentType.ReadOnly = false;
      contentType.Update(true);
    
      contentType.DocumentTemplate = template;
      contentType.ReadOnly = true;
      contentType.Update(true);
    
      Console.WriteLine(String.Format("Updated '{0}'.", contentType.Name));
    }
    I'm wondering if I can attach the same functionality to the Feature and have the code run when the Feature is activated. Hope this helps someone.
    • Marked as answer by Ryan Ball Thursday, April 8, 2010 10:55 AM
    Thursday, April 8, 2010 10:54 AM