Skip to content

Commit e4705dc

Browse files
Update Program.cs
1 parent 35863f2 commit e4705dc

File tree

1 file changed

+6
-3
lines changed
  • Mail-Merge/Generate-Documents-for-each-record/.NET/Generate-Documents-for-each-record

1 file changed

+6
-3
lines changed

Mail-Merge/Generate-Documents-for-each-record/.NET/Generate-Documents-for-each-record/Program.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Syncfusion.DocIO;
1+
using Syncfusion.DocIO;
22
using Syncfusion.DocIO.DLS;
33
using System.Data;
44
using System.IO;
@@ -13,13 +13,15 @@ static void Main(string[] args)
1313
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open))
1414
{
1515
//Load file stream into Word document.
16-
using (WordDocument document = new WordDocument(fileStream, FormatType.Docx))
16+
using (WordDocument template = new WordDocument(fileStream, FormatType.Docx))
1717
{
1818
//Get the data for mail merge.
1919
DataTable table = GetDataTable();
2020
//Iterate to the each row and generate mail merged document for each rows.
2121
for (int i = 0; i < table.Rows.Count; i++)
2222
{
23+
//Clones the template document for creating new document for each record in the data source
24+
WordDocument document = template.Clone();
2325
//Executes mail merge using the data row.
2426
document.MailMerge.Execute(table.Rows[i]);
2527

@@ -29,6 +31,8 @@ static void Main(string[] args)
2931
//Save the Word document to the file stream.
3032
document.Save(outputFileStream, FormatType.Docx);
3133
}
34+
//Releases the resources occupied by WordDocument instance
35+
document.Dispose();
3236
}
3337
}
3438
}
@@ -67,4 +71,3 @@ static DataTable GetDataTable()
6771
}
6872
}
6973
}
70-

0 commit comments

Comments
 (0)