I'm working with a Console App that merges a DocX file from a template.
I'm using TemplateEngine.Docx and it almost works fine.
When I save my document from a stream, the file is corrupted. I can open it and everything is okay, but I've got an alert when opening it.
I think it's because I don't set a content type, but I don't know how to do it with a stream/FileStream.
A sample of my code :
Stream outputFile = GetFileFromId(6);
using(var outputDocument = new TemplateProcessor(outputFile).SetRemoveContentControls(true))
{
outputDocument.FillContent(valuesToFill);
outputDocument.SaveChanges();
outputDocument.Document.Save(outputFile);
FromStreamToFile(outputFile, OutputFilename);
}
public static void FromStreamToFile(Stream stream, string OutputFilePath)
{
using(var fileStream = File.Create(OutputFilePath))
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
}
}
Thanks for your help !