Free Support Forum - aspose.com

Cannot get new line

Hi,

i am maergind data to a template, my data , i have to divide it to seperate line. to whereveer i need to sepearate, i plcaed a /end/. so my datat is seprated with /end/.

So while merging i replaced it with \r\n for a new line, but i am not getting a new line.
What to do to get a new line.
My data coming is in this format.
this is test1/end/. this is test2/end/.

The output after merging should be.
this is test1
this is test2.

how to do it?

Hi

Thanks for your inquiry. I think that you can use the following code.

public void TestMailMerge_106437()

{

Document doc = new Document(@"278_106437_raviteja\in.doc");

string[] names = { "test" };

string[] values = { "this is test1./*end*/this is test2./*end*/" };

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField_106437);

doc.MailMerge.Execute(names, values);

doc.Save(@"278_106437_raviteja\out.doc");

}

void MailMerge_MergeField_106437(object sender, MergeFieldEventArgs e)

{

if (e.FieldValue.ToString().Contains("/*end*/"))

{

DocumentBuilder builder = new DocumentBuilder(e.Document);

builder.MoveToMergeField(e.FieldName);

builder.Write(e.FieldValue.ToString().Replace("/*end*/", "\r\n"));

}

}

I hope that this will help you.

Best regards.