I had to generate a document from a template. I have a Content Type with associated a Template (a .dotx file). How can I do to create a document (programmatically) from that template?
I tried this way:
SPList clienti = web.Lists["LISTNAME"];
SPContentType ct = web.ContentTypes["CTNAME"];
var file = web.GetFile(ct.DocumentTemplateUrl);
SPFile fileAppenaAggiunto = clienti.RootFolder.Files.Add("nomeDaProg12.docx", file.OpenBinaryStream());
SPListItem appenaAggiunto = fileAppenaAggiunto.Item;
appenaAggiunto["ContentTypeId"] = clienti.ContentTypes["CTNAME"].Id;
appenaAggiunto["FIELD1"] = "asd";
appenaAggiunto["FIELD2"] = "Bozza";
appenaAggiunto.Update();
I found a document in my DocLib that equals to the source template but it is still a Template so if I tried to open it the system tolds me there is an error. If I rename it to dotx, it works as template.
Any suggestion? There is another way to "deploy" a doc from a given template doc programmatically?
Thank you