Free Support Forum -

Seperate as a individual document while doing mail merge

This is Radha from Singapore.
I can create a Merge file from the Dataset.I need seperate document for seperate record.So I have used below code in C#.

string strTemplateFile =Request.PhysicalApplicationPath + "Reminders/Templates/"+ StrReportName;
string strDatafile =Request.PhysicalApplicationPath + "Reminders/Data/"+ StrReportName.Replace(".doc",".dat").Trim();
string strMMfile =Request.PhysicalApplicationPath + "Reminders/RemindersOutput/"+ StrReportName;
Word word = new Word();
Document doc = word.Open(strTemplateFile);

//Fill the fields in the document with user data.


DataSet DSMM= ClsRmdr.GetMMData();---> Dataset contains data from executing Stored Procedures

for ( r = 8; r< Convert.ToInt32(DSMM.Tables[0].Columns.Count) ; r++)
mycol= new DataColumn();
mycol.DataType = System.Type.GetType ( "System.String" );
mycol.ColumnName = DSMM.Tables[0].Columns[r].Caption.ToString();
MyDT.Columns.Add ( mycol );
for ( i = 0; i< Convert.ToInt32(DSMM.Tables[0].Rows.Count) ; i++)
int x=0;
MyRow= MyDT.NewRow();
for ( int j = 8; j < Convert.ToInt32(DSMM.Tables[0].Columns.Count.ToString()) ; j++)
MyRow[x]= DSMM.Tables[0].RowsIdea.ItemArray[j].ToString();


strMMfile =Request.PhysicalApplicationPath + "Reminders/RemindersOutput/";
StrSplit = StrReportName.Substring(0,(StrReportName.Length)-4);

if (i == 0)
StrSplit = StrSplit + "-01"+".doc";
strMMfile = strMMfile + StrSplit;
Count = Count + 1;
StrSplit = StrSplit + "-0" + Convert.ToString(Count)+".doc";
strMMfile = strMMfile + StrSplit;

doc.Save(strMMfile, SaveFormat.FormatDocument);

I got seperate two Individual files.But both Document contains same data.
Plase help me to do

Please mail me

I sort of understand what you are trying to do in your code, but sorry, it seems too complicated for me to understand it fully. I can give you are couple of hints that might help:

1. When you open a document and mail merge into it - the merge fields are replaced with data. The key here is the merge fields are gone after the mail merge and this document cannot be used as a template for another mail merge. It might be the case in your scenario although I cannot fully see it. You need to either reopen the template document or clone it in memory before mail merge.

2. Instead of recreating data row programmatically, you can use DataView and filter your DataTable to the record you want and mail merge with DataView, then change the filter and do another mail merge.