Created
January 19, 2016 13:43
-
-
Save bjoerntx/f244b0b99f0600b55241 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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