Moreover, to insert a Hyperlink instead of plain text, please try using the DocumentBuilder.InsertHyperlink method inside IFieldMergingCallback.FieldMerging event as follows:
Hi,
What I need is to replace the mergefield <> with the Text from the XML (like any other mail merge field) but I don’t know how to place the the url behind with the Url vale from the XML. I don’t get how InsertHyperlink help in this case. Please give more information.
Thank you.
Regards
private class HandleMergeFieldAlternatingRows : IFieldMergingCallback
{
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
if (mBuilder == null)
mBuilder = new DocumentBuilder(e.Document);
if (e.FieldName.Equals("mergefield"))
{
mBuilder.MoveToMergeField(e.FieldName);
// I think, if you need a custom Text for the link, you have to query again here:
mBuilder.InsertHyperlink(e.FieldValue.ToString(), e.FieldValue.ToString(), false);
}
}
public void ImageFieldMerging(ImageFieldMergingArgs args)
{
throw new NotImplementedException();
}
private DocumentBuilder mBuilder;
}
If we can help you with anything else, please feel free to ask.
Hi,
Thanks for the code, but I still confused here
doc.MailMerge.Execute(new string[] { "mergefield" }, new object[] { "http://www.aspose.com/" });
This is not used anywhere, especially the url "http://www.aspose.com/
In the function, you specifically check the mergefield name, it is not the field passed from somewhere else. Anyway, I just try to put my mergefield name there, and the value of that mergefield becomes the hyperlink. But still it is not what I really want. Please look at my xml in the first note, so what I need to achieve is to have
This is the text to display as an hyperlink and when you hover over it you will see the url http://theurl.com and I don’t know how to do it. Thank you.
First, to be able to achieve what you are looking for, I would like to suggest you to please change the structure of your XML data source file to the following:
Hi,
Thank you for the code, but I have to change it a bit to make it work for me. So it’s all good. But one more thing I want to ask why it’s not appear as the link (eg Test)with the underline, it is just appeared as a normal text “Test” unless you hover it then you can see it’s a hyperlink. Thank you.