Hello there,
I am facing an error while calling MailMerge.ExecuteWithRegions(List).
Attached is my source document in which I have two table regions defined:
TableStart:Properties
TableStart:Applicants
TableEnd:Applicants
TableEnd:Properties
and my data source is a List, where T is my Business Entity.
Every T is having a collection of child objects say, Applicants.
So, I have implemented IMailMergeDataSource as below:
public class PropertyMailMergeDataSource: IMailMergeDataSource
{
private List _propertyList;
private int recordIndex;
private bool IsEof
{
get
{
return (recordIndex>= _propertyList.Count);
}
}
public PropertyMailMergeDataSource(List properties)
{
this._propertyList = properties;
recordIndex = -1;
}
#region IMailMergeDataSource Members
bool IMailMergeDataSource.GetValue(string fieldName, out object fieldValue)
{
var pInstruction = (_propertyList[recordIndex] as BasePropertyInstruction);
fieldValue = null;
try
{
switch (fieldName.ToUpper())
{
#region Property fields
case "PASKINGPRICE":
fieldValue = pInstruction.AskingPrice;
return true;
...
so on with mutiple
case statements
#endregion
default:
fieldValue = "##FIELD DOES NOT EXIST##";
return true;
}
}
catch (Exception ex)
{
fieldValue = "## FIELD: " + fieldName + " DOES NOT EXIST##";
return true;
}
}
bool IMailMergeDataSource.MoveNext()
{
if (!IsEof)
{
recordIndex++;
}
return (!IsEof);
}
string IMailMergeDataSource.TableName
{
get
{
return "Properties";
}
}
public IMailMergeDataSource GetChildDataSource(string tableName)
{
var pInstruction = (_propertyList[recordIndex] as BasePropertyInstruction);
switch (tableName)
{
case "Applicants":
return new ApplicantsDataSource(pInstruction.Applicants.ToList());
default:
return null;
}
}
#endregion
}
I have implemented IMailMergeDataSource again for ApplicantsDataSource similar as above with TableName as:
public string TableName
{
get
{
return "Applicants";
}
}
However when I am calling MailMerge.ExecuteWithRegions, it is throwing error after going over line in red color.
The error details are:
"Value cannot be null.\r\nParameter name: startParent"
"at Aspose.Words.CompositeNode.(Node, Node, Node, Node)
at Aspose.Words.CompositeNode.(Node, CompositeNode, Node, CompositeNode, Boolean)
at Aspose.Words.Fields.Field.Remove()\r\n
at (MailMerge, IMailMergeDataSource)\r\n at (ArrayList)\r\n
at (MailMerge, IMailMergeDataSource)\r\n
at Aspose.Words.Reporting.MailMerge.ExecuteWithRegions(IMailMergeDataSource dataSource)
Please help.