We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Obtaining the Underlying Data Source during a mailmerge

I’m using a custom IFieldMergingCallback class to handle some specific scenarios during a mailmerge. I have the basic functionality working (manipulating the text and setting the value of the merge field). What I would like to do now is obtain an instance of the underlying DataRow that the merge field is pulling data from within the FieldMerging method. I know I can pass in the full DataSet when the class is initialized, but I won’t know what row is currently being processed when the FieldMerging method is called. Is there a way to get at the underlying data source?



Thanks for your inquiry. You can pass datasource to class implementing the IFieldMergingCallback interface via its default constructor and then inside IFieldMergingCallback.FieldMerging method use FieldMergingArgsBase.RecordIndex property to obtain the zero based index of the record that is being merged. I hope, this helps.

Best regards,

There is a problem with this approach. The RecordIndex property returns the index in relation to the parent, not in the table itself. For instance, if I had the XML structure below:

child 1
child 2
The DataSet that is passed into the Document object will contain a “child” table with 2 records in it. When the FieldMerging method is called with “child2” as the FieldValue, the RecordIndex value will be 0 instead of 1 because it is the first record under its parent. Since I don’t have any context as to the parent’s of the current field, I still don’t know how to get the current record that the field belongs to.


Thanks for the additional information. I have logged your requirement in our issue tracking system as WORDSNET-10151. Our development team will further look into the details of this problem and we will keep you updated on the status of this issue. We apologize for your inconvenience.

Best regards,


Regarding WORDSNET-10151, our product team has completed the work on your issue and has come to a conclusion that they won’t be able to implement the fix to your issue. Your issue (WORDSNET-10151) has now been closed with ‘Won’t Fix’ resolution. Please see the following analysis details:

There are many different types of supported data sources:

  • ADO types (DataTable, DataRow, DataView, DataSet)
  • string[]+object[]
  • IMailMergeDataSource, IMailMergeDataSourceRoot

The only way to provide underlying data source via IFieldMergingCallback is to extend the FieldMergingArgs with property of base object type. Our product team has decided that it does not worth to implement such feature. We apologize for any inconvenience and thank you for your understanding.

Best regards,