We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Linking a csv data source to a Word document

Thread ID:





80753 Apr 25,2009 10:50 AM UTC Apr 29,2009 10:42 AM UTC WinForms 3
Tags: DocIO
Benoit de Bernardy
Asked On April 25, 2009 10:50 AM UTC


I would like to know whether it's possible to link a csv file to a Word document programmatically using DocIO.

Under MS Word, you can select a list of recipients (an OLDB data source, csv file, etc...). MS Word analyzes this data source and creates a list of available fields to merge.

What I would like to do is link my Word document to a csv file that will be used as the list of recipients.

Thank you for your help,


Bhuvaneswari P [Syncfusion]
Replied On April 27, 2009 07:39 AM UTC

Hi Gnarl,

Thank you for your inquiry.

Currently we don't have direct support for Mail merge using CSV format. But it can be workaround by converting the CSV file to DataTable using .Net and then pass this table for mail merge.

Please refer the below code snippet to do so:

doc.MailMerge.Execute(csvToDataTable(@"..\..\test1.csv",true ));

public static DataTable csvToDataTable(string file, bool isRowOneHeader)

DataTable csvDataTable = new DataTable();

//no try/catch - add these in yourselfs or let exception happen
String[] csvData = File.ReadAllLines(file);

//if no data in file ‘manually’ throw an exception
if (csvData.Length == 0)
throw new Exception("CSV File Appears to be Empty");

String[] headings = csvData[0].Split(',');
int index = 0; //will be zero or one depending on isRowOneHeader

if (isRowOneHeader) //if first record lists headers
index = 1; //so we won’t take headings as data

//for each heading
for (int i = 0; i < headings.Length; i++)
//replace spaces with underscores for column names
headings[i] = headings[i].Replace(" ", "_");

//add a column for each heading
csvDataTable.Columns.Add(headings[i], typeof(string));
else //if no headers just go for col1, col2 etc.
for (int i = 0; i < headings.Length; i++)
//create arbitary column names
csvDataTable.Columns.Add("col" + (i + 1).ToString(), typeof(string));

//populate the DataTable
for (int i = index; i < csvData.Length; i++)
//create new rows
DataRow row = csvDataTable.NewRow();

for (int j = 0; j < headings.Length; j++)
//fill them
row[j] = csvData[i].Split(',')[j];

//add rows to over DataTable

//return the CSV DataTable
return csvDataTable;


Please refers to the below sample which illustrate how to mail merge using CSV file:

Please try this and let us know if this helps you.

Best Regards,

Benoit de Bernardy
Replied On April 28, 2009 07:43 AM UTC

Thank you Bhuvana for the quick reply.

Unfortunately, it was not an answer to the question I asked.
I’ll try to rephrase my question differently.
I got the Doc.MailMerge.Execute method to work just fine. I’m not looking for help on this part.

Under Microsoft Word, when you want to do a mail merge, you first have to select the data source. Once you have selected this data source, you get a list of all the available fields and you can add these fields into your Word document using drag and drop.
When you close a document for which you have specified a data source, when you open the document again, Microsoft Word is able to find the OLEDB data source you had specified which means that it’s stored somewhere in your Word document. That’s the information I’m trying to locate.

Bhuvaneswari P [Syncfusion]
Replied On April 29, 2009 10:42 AM UTC

Hi Gnarl,

Thanks for more details.

I could understand your requirement. Unfortunately, there is no way to link document to Mail Merge DataSource using our Essential DocIO. We don't have any immediate plan implement this feature in our near future.

You can only perform Mail Merge programmatically as sample given in the previous update.

For more information please refer the below documentation link for DocIO mail merge features.

Please let us know if you need any further details.

Best Regards,


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon