I am fundamentally doing something wrong here within this loop. The first time through the loop, the Stream works fine, but subsequent times through the loop fail with the Stream being corrupted. I know am probably doing something silly. I tried to set the updateTemplate to 0 each time but the InputStream doesn’t support the seek. I am basically appending multiple forms that are filled in onto a List here. Any suggestions would be appreciated, especially ones that would result in better performance.
...
files.Add(PDFhelper.fillTemplate(template, mappings));
foreach (Update u in myObject.Updates)
{
mappings = this.GenerateFieldMappings(u);
Stream output = new MemoryStream();
template.CopyTo(output);
files.Add(PDFhelper.fillTemplate(output, mappings)); //First time stream is good
}
return PDFhelper.MergeFiles(files);
...
Well, here is one solution I found. although, I don’t find it very efficient. It does get the job done.