File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Mail-Merge/Generate-Documents-for-each-record/.NET/Generate-Documents-for-each-record Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1- using Syncfusion . DocIO ;
1+ using Syncfusion . DocIO ;
22using Syncfusion . DocIO . DLS ;
33using System . Data ;
44using 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-
You can’t perform that action at this time.
0 commit comments