Hi,
I've found a problem with a MailMerge and a list ExpandoObject as datasource. After switching to Result display mode, it appears to replace the MergefFields with string.empty.
Dynamic object with "static written" property works fine.
Problem seems to be the same as described here: http://www.telerik.com/forums/dynamic-mailmerge
Please apply the same fix in WinForms.
Regards, Tomasz.
3 Answers, 1 is accepted
Thank you for writing.
Indeed this is currently not working in the WinForms RichTextEditor. I have logged a feature request for it in our Feedback Portal. I have added a vote for it on your behalf as well. You can track its progress, subscribe for status changes and add your comment to it here. I have also updated your Telerik Points.
In addition, I have attached a sample project that shows how you can implement something similar.
Please do not hesitate to contact us with any additional questions or concerns.
Regards,
Dimitar
Telerik by Progress
Hi Dimitar,
Ok, I can build and run your sollution and indeed it shows that you can insert custom mergefields in doc file by UI (what was not exactly the point) BUT... if you insert those fields by UI and hit "Preview Results" the mergefielgs are replaced by nothing (string.empty) instead of strings defined in code - what is exactly the point :)
Thx for feature request (imo bug request btw).
Regards, Tomasz.Yes, I can confirm that the merge operation is not working. It appears that the example only shows how you can replace the insert merge field button. So to make this work you need to create a custom merge field and return a proper value:
class MyMergeField : MergeField{ private static readonly string FieldType = "DYNAMIC_FIELD"; static MyMergeField() { CodeBasedFieldFactory.RegisterFieldType(MyMergeField.FieldType, () => new MyMergeField()); } public override Field CreateInstance() { return new MyMergeField(); } public override string FieldTypeName { get { return MyMergeField.FieldType; } } protected override DocumentFragment GetResultFragment() { // return base.GetResultFragment(); string valueAsString = null; if (this.Document != null && !string.IsNullOrEmpty(this.PropertyPath)) { object currentItem = this.Document.MailMergeDataSource.CurrentItem; if (currentItem != null) { object value = ""; var dataObject = currentItem as MyDynamicObject; value = dataObject.Get(this.PropertyPath); valueAsString = this.ConvertToString(value); } } if (!string.IsNullOrEmpty(valueAsString)) { valueAsString = this.TextBeforeIfNotEmpty + valueAsString + this.TextAfterIfNotEmpty; } DocumentFragment resultFragment = base.CreateFragmentFromText(valueAsString); return resultFragment; }}I hope this will be useful.
Regards,
Dimitar
Telerik by Progress
