Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using a complete 2010 environment (SP,VS and Word) but when I provision my content type using XML, while it provisions everything and appears to work, when I create a new Word document from my content type it decides not to hold the Content Type when I save it…has anyone got a working example of this in 2010?

I am storing the document template in the _cts folder, provisioning all content type info in XML.

I am provisioning a document library and assigning the content type to it using code…

I am currently investigating if provisioning the Content Type in code makes a difference…

share|improve this question
    
Are you able to post the content type XML and a screenshot of the save dialog? –  Alex Angas Jun 29 '11 at 6:41
    
does your library defines several content types ? –  Steve B Jun 29 '11 at 7:35
add comment

1 Answer

God bless Reflector!! Maybe I should have tried this one earlier rather than that crappy* “Import SharePoint Solution Package” tool that led me down the garden path!!

I had been trying to add the document template file to a folder and document in the _cts folder like the “Import SharePoint Solution Package” tool (and every other blog site) was doing and linking my content type to the file and was getting nowhere.

So I decided to see how SharePoint actually does it from the ChangeContentTypeOptionalSettings.aspx page See below is an extract from Microsoft.SharePoint.ApplicationPages.dll  ChangeContentTypeOptionalSettingsPage  OnSubmit  UpdateContentType

The two lines of paramount importance are highlighted

        HttpPostedFile file = base.Request.Files[0];
        if ((file.FileName.Length > 0) && (file.ContentLength > 0))
        {
            string fileName = file.FileName;
            fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
            base.ContentType.ResourceFolder.Files.Add(fileName, file.InputStream, true);
            base.ContentType.DocumentTemplate = fileName;
            flag = true;
        }
        else
        {
            base.ContentType.DocumentTemplate = "";
            flag = true;
        }

This has resolved the issue with Word documents, I still need to find a solution for Visio documents…this is my next battle…

Thanks to all those people whom provided ideas and feedback, as always it is much appreciated!

*I am sure that the “Import SharePoint Solution Package” tool has its place…but content types and document templates it not something it does well…use with caution!

share|improve this answer
    
So what was the actual problem here? I have the same problem. –  user5291 Oct 19 '11 at 5:41
    
Same here, not understanding the solution –  masenkablast Apr 4 '12 at 18:53
    
It means that before he had used the "Import SharePoint Solution Package" tool to generate the code he used to add the template document, but that code created the error he was experiencing. He then tried to use another way to do what he needed and copied it from a SharePoint page codebehind (as now as "you don't have the sample, let Reflector create the sample ^_^) and it worked. So if you belive you may be in the situation he described, have a go at the posted code and see if the behaviour change. –  SPArchaeologist Nov 9 '12 at 9:17
    
BTW, @Daniel, you may want to add the code/caml/whatever that you used before as a comparision with the modified one. –  SPArchaeologist Nov 9 '12 at 9:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.