This is a migrated thread and some comments may be shown as answers.

MailMerge with ExpandoObject

3 Answers 110 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Tomasz Zawadzki
Top achievements
Rank 1
Tomasz Zawadzki asked on 14 Oct 2016, 12:43 PM

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

Sort by
0
Dimitar
Telerik team
answered on 17 Oct 2016, 11:04 AM
Hi Tomasz,

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
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Tomasz Zawadzki
Top achievements
Rank 1
answered on 18 Oct 2016, 07:25 AM

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.
0
Dimitar
Telerik team
answered on 18 Oct 2016, 12:34 PM
Hello 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
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
RichTextEditor
Asked by
Tomasz Zawadzki
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Tomasz Zawadzki
Top achievements
Rank 1
Share this question
or