private static DataSet CreateDataSourceFromDocumentRegions(Document doc, ArrayList regionsList)
{
const string tableStartMarker = "TableStart:";
DataSet dataSet = new DataSet();
string tableName = null;
foreach (string fieldName in doc.MailMerge.GetFieldNames())
{
if (fieldName.Contains(tableStartMarker))
{
tableName = fieldName.Substring(tableStartMarker.Length);
}
else if (tableName != null)
{
// Only add the table name as a new DataTable if it doesn't already exists in the DataSet.
if (dataSet.Tables[tableName] == null)
{
DataTable table = new DataTable(tableName);
table.Columns.Add(fieldName);
// We only need to add the first field for the handler to be called for the fields in the region.
if (regionsList == null || regionsList.Contains(tableName))
{
table.Rows.Add("FirstField");
}
dataSet.Tables.Add(table);
}
tableName = null;
}
}
return dataSet;
}
// ExEnd:CreateDataSourceFromDocumentRegions