We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

I am unable to MailMerge the fields

Helloo

I am unable to merge the fields into my document

here is the my code

Form 1: Here I am inserting the field into table

DataTable dt=new DataTable();

//sungard information

dt.Columns.Add("SGFirstName",typeof(System.String));

dt.Columns.Add("SGMI",typeof(System.String));

dt.Columns.Add("SGLastName",typeof(System.String));

dt.Columns.Add("SGTitle",typeof(System.String));

dt.Columns.Add("SGAddress1",typeof(System.String));

dt.Columns.Add("SGAddress2",typeof(System.String));

dt.Columns.Add("SGCity",typeof(System.String));

dt.Columns.Add("SGState",typeof(System.String));

dt.Columns.Add("SGZipcode",typeof(System.String));

dt.Columns.Add("SGCountry",typeof(System.String));

dt.Columns.Add("SGPhone",typeof(System.String));

dt.Columns.Add("SGFax",typeof(System.String));

dt.Columns.Add("SGEmail",typeof(System.String));

//client information

dt.Columns.Add("CCompanyLegalName",typeof(System.String));

dt.Columns.Add("CCompanyShortName",typeof(System.String));

dt.Columns.Add("CSalution",typeof(System.String));

dt.Columns.Add("CFirstName",typeof(System.String));

dt.Columns.Add("CMI",typeof(System.String));

dt.Columns.Add("CLastName",typeof(System.String));

dt.Columns.Add("CTitle",typeof(System.String));

dt.Columns.Add("CAddress1",typeof(System.String));

dt.Columns.Add("CAddress2",typeof(System.String));

dt.Columns.Add("CCity",typeof(System.String));

dt.Columns.Add("CState",typeof(System.String));

dt.Columns.Add("CZipcode",typeof(System.String));

dt.Columns.Add("CCountry",typeof(System.String));

dt.Columns.Add("CPhone",typeof(System.String));

dt.Columns.Add("CFax",typeof(System.String));

dt.Columns.Add("CEmail",typeof(System.String));

DataRow dr=dt.NewRow();

dr["SGFirstName"]=txtFirstName.Text;

dr["SGMI"]=txtMI.Text;

dr["SGLastName"]=txtLastName.Text;

dr["SGTitle"]=txtTitle.Text;

dr["SGAddress1"]=txtAddress1.Text;

dr["SGAddress2"]=txtAddress2.Text;

dr["SGCity"]=txtCity.Text;

dr["SGState"]=txtState.Text;

dr["SGZipcode"]=txtZip.Text;

dr["SGCountry"]=txtCountry.Text;

dr["SGPhone"]=txtPhone.Text;

dr["SGFax"]=txtFax.Text;

dr["SGEmail"]=txtEmailAddress.Text;

dr["CCompanyLegalName"]=txtCompanyLegalName.Text;

dr["CCompanyShortName"]=txtCompanyShortName.Text;

dr["CSalution"]=txtCompanyShortName.Text;

dr["CFirstName"]=txtCFirstName.Text;

dr["CMI"]=txtCMI.Text;

dr["CLastName"]=txtCLastName.Text;

dr["CTitle"]=txtCTitle.Text;

dr["CAddress1"]=txtCAddress1.Text;

dr["CAddress2"]=txtCAddress2.Text;

dr["CCity"]=txtCCity.Text;

dr["CState"]=txtCState.Text;

dr["CZipcode"]=txtCZip.Text;

dr["CCountry"]=txtCCountry.Text;

dr["CPhone"]=txtCPhone.Text;

dr["CFax"]=txtCFax.Text;

dr["CEmail"]=txtCEmailAddress.Text;

Session["formValues"]=dr;

Form2: Through session here Iam getting mail merge fields

DataRow dr = (DataRow)Session["formValues"];

newdoc1.MailMerge.Execute(dr);

newdoc1.MailMerge.DeleteFields();

//inserting table of contents

Aspose.Words.Document testdoc = new Aspose.Words.Document();

DocumentBuilder builder = new DocumentBuilder(newdoc1);

builder.MoveToSection(1);

builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

testdoc =newdoc1;

testdoc.Range.UpdateFields();

testdoc.Save("AutoGenerated.doc", SaveFormat.Doc, SaveType.OpenInWord, this.Response);

// imgDoc.Save("AutoGenerated.doc", SaveFormat.Doc, SaveType.OpenInWord, this.Response);

Response.Flush();

Error:Stack Empty;

Hi

Thanks for your inquiry. I tried using the attached code for testing and it seems that all works fine on my side. Please make sure that there is data in the Session variable. Also you can create sample application that will allow me to reproduce this problem.

Best regards.