Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created January 19, 2016 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/f244b0b99f0600b55241 to your computer and use it in GitHub Desktop.
Save bjoerntx/f244b0b99f0600b55241 to your computer and use it in GitHub Desktop.
[HttpPost]
public string Merge(DocumentViewModel model)
{
// convert the template to a byte array
byte[] document =
Convert.FromBase64String(model.BinaryDocument);
// load the the data source
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("/App_Data/data/sample_db.xml"),
XmlReadMode.Auto);
byte[] sDocument;
// create a new ServerTextControl and MailMerge component
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
MailMerge mm = new MailMerge();
mm.TextComponent = tx;
// load the template and merge
mm.LoadTemplateFromMemory(document,
FileFormat.InternalUnicodeFormat);
mm.Merge(ds.Tables[0], true);
// save the document
mm.SaveDocumentToMemory(out sDocument,
TXTextControl.BinaryStreamType.InternalUnicodeFormat, null);
}
// encode and return the merged document
return Convert.ToBase64String(sDocument);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment