Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active August 29, 2015 14:25
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/cf00d693f35c72e7ce23 to your computer and use it in GitHub Desktop.
Save bjoerntx/cf00d693f35c72e7ce23 to your computer and use it in GitHub Desktop.
Form1
private string sDataSource = "data.xml";
private string sTemplateFile = "template.tx";
private void mergeToolStripMenuItem_Click(object sender, EventArgs e)
{
// convert the XML file to a .NET DataSet
DataSet ds = new DataSet();
ds.ReadXml(sDataSource, XmlReadMode.Auto);
// create a new DataSelector instance
DataSelector selector = new DataSelector(ds,
File.ReadAllBytes(sTemplateFile));
// load the modified template
mailMerge1.LoadTemplateFromMemory(selector.Template,
TXTextControl.DocumentServer.FileFormat.InternalUnicodeFormat);
// merge the template with the new, sorted data source
mailMerge1.Merge(ds.Tables[0]);
// copy the merged document into a visible TextControl object
byte[] data = null;
mailMerge1.SaveDocumentToMemory(out data,
TXTextControl.BinaryStreamType.InternalUnicodeFormat, null);
textControl1.Load(data,
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment