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. Image for the cookie policy date
close icon

Could my .Net Core class library use Syncfusion.DocIO API?

Dear Support,

My ASP.NET Core project uses reference from a .Net Core class library. Basically I want to know whether I could use your MailMerge in DocIO?

https://help.syncfusion.com/file-formats/docio/working-with-mailmerge


If I can, which Nuget package to add? As I saw a lot online in Visual Studio. If not, is there any work around?


Thanks a lot!


7 Replies

SY Sethumanikkam Yogendran Syncfusion Team December 19, 2016 05:56 AM UTC

Hi Samuel,

Thank you for contacting Syncfusion support.

We have prepared a sample to illustrate simple Mail merge with DocIO in ASP.NET Core application. Please find the below sample which illustrate the same and let us know if it helps you.
http://www.syncfusion.com/downloads/support/forum/127918/ze/DocIOApplication-F127918-916226595.zip

If I can, which Nuget package to add?
Following Nuget packages are need to add.
 
Package Name 
Short Description 
Syncfusion.Compression.AspNet.Core 
This package is used to archive/extract the Word document contents. 
Syncfusion.OfficeChart.AspNet.Core 
This package contains the Office Chart Object model and core features needed for chart creation. 
Syncfusion.DocIO.AspNet.Core 
This package contains the core features needed for creating, reading, manipulating a Word document. 

Please refer the following online sample link to know more about how to perform Mail merge.
http://aspnetcore.syncfusion.com/docio/nestedmailmerge

Please refer the following UG documentation about ASP.NET Core.
https://help.syncfusion.com/aspnet-core/getting-started
https://help.syncfusion.com/aspnet-core/docio/getting-started

Please find online nuget packages from below link.
http://nuget.syncfusion.com/package/aspnetcore

Please let us know if you have any other questions.

Thanks,
Sethumanikkam.Y



SA Samuel December 19, 2016 11:08 PM UTC

Hi Sethumanikkam,

Thanks for your reply.

If I use the last link you provide to install Nuget package, the top 3 you mentioned in the post could not be found.


But anyway I will try to look for them, and let you know whether it works or not.



SA Samuel December 20, 2016 03:22 AM UTC

Hi Sethumanikkam,

The package is OK now.  There are still 2 questions:

1) I know to use document.MailMerge.GetMergeFieldNames() to get list of merge fields name, but how to get the list of values for these fields?

2) Althernatively, we want to keep the value in word document but remove merge fields from it, how to do it?


I found if I use:
document.MailMerge.Execute(fieldNames, fieldValues), it can do what we want. But again I need the list of values.


Thanks again!





SY Sethumanikkam Yogendran Syncfusion Team December 20, 2016 06:17 AM UTC

Hi Samuel,

Thank you for your update.

1) I know to use document.MailMerge.GetMergeFieldNames() to get list of merge fields name, but how to get the list of values for these fields?
The following data sources are supported by Essential DocIO for performing Mail merge in ASP.NET Core.
     1. String Arrays
     2. Dynamic objects
     3. Business objects

2) Alternatively, we want to keep the value in word document but remove merge fields from it, how to do it?
The “MailMerge” class provides various overloads as for methods to perform Mail merge as per need in ASP.NET Core.
Execute(IEnumerable dataSource);
Execute(string[] fieldNames, string[] fieldValues);
ExecuteGroup(MailMergeDataTable dataSource);
ExecuteNestedGroup(MailMergeDataTable dataTable);
ExecuteNestedGroup(MailMergeDataSet dataSource, List<DictionaryEntry> commands);

I found if I use: document.MailMerge.Execute(fieldNames, fieldValues), it can do what we want. But again, I need the list of values.
It’s not possible to get field values of Mail merge fields once after executing “MailMerge”. We have prepared a sample to meet your requirement. In this sample, we have done the following.

1. Created a Word template document with merge fields.
2. Performed a simple Mail merge in the generated template document with string array as data source.
3. Using MergeField Event, retrieved the list of field values.
4. Saved as Word document

Please find the sample from below link and let us know if it helps you.
http://www.syncfusion.com/downloads/support/forum/127918/ze/DocIOApplication-F127918-11405915800.zip

Please refer the following links to know more about working with Mail merge.
https://help.syncfusion.com/file-formats/docio/working-with-mailmerge
https://help.syncfusion.com/file-formats/docio/working-with-mailmerge#event-support-for-mail-merge
https://help.syncfusion.com/file-formats/docio/working-with-mailmerge#mail-merge-options

If we misunderstood your requirement, kindly update us requirement with clear description. Thereby we will analyze further on the mentioned requirement and update you with appropriate solution.

Please let us know if you have any other questions.

Thanks,
Sethumanikkam.Y



SA Samuel December 21, 2016 12:06 AM UTC

Hi Sethumanikkam,

The sample you sent me is actually not 100% what we are after. If we already knew the fields value, why do we need to get it again from event? :-)


Let me paste the method we previously used for other commercial API. They could get the fields value, so when executing it, word document will remove those merge fields but leave static value only. From business point of view we could give these documents to client without containing our company's merged fields. (But unfortunately this API doesn't support .Net Core at this stage.)



        public static bool ConvertMergeFieldsToStaticText(Document documentToProcess, string saveFilePath = null)
        {
            var mergeFields = documentToProcess.MailMerge.GetFieldNames();

            while (mergeFields.Any())
            {
                var fields = documentToProcess.Range.Fields.Cast<Field>().Where(field => field.Type == FieldType.FieldMergeField);

                var fieldValues = fields.Select(field => field.Result).Cast<object>().ToArray();


                foreach (var field in fields)
                {
                    field.Remove();
                }

                documentToProcess.MailMerge.Execute(mergeFields, fieldValues);             
            }

            documentToProcess.Save(!string.IsNullOrWhiteSpace(saveFilePath) ? saveFilePath : documentToProcess.OriginalFileName);

            return true;
        } 




But doing this, all merge fields will be replaced with static text. Is there any similar way in Syncfusion we could archive what brown line does?


Thanks again!

Samuel


SY Sethumanikkam Yogendran Syncfusion Team December 21, 2016 09:04 AM UTC

Hi Samuel,

Thank you for your update.

Is there any similar way in Syncfusion we could archive what brown line does?
Yes. We have prepared a sample to meet your requirement with the following steps.
1. Load template Word document and get merge field names.
2. Retrieve merge field values by iterating through document elements.
3. Perform Mail merge and save as Word document.

Please find the below sample which illustrates the same, and let us know if it helps you.
http://www.syncfusion.com/downloads/support/forum/127918/ze/DocIOApplication-F127918-2-1270809338.zip

Please refer the following links to know more about working with fields and iteration in document elements.
https://help.syncfusion.com/file-formats/docio/working-with-fields
https://help.syncfusion.com/file-formats/docio/working-with-word-document#iterating-through-document-elements

If we misunderstood any of your requirement, kindly update us requirement with clear description. Thereby we will analyze further on the mentioned requirement and update you with appropriate solution.

Please let us know if you have any other questions.

Thanks,
Sethumanikkam.Y



SV Sivasubramani V Syncfusion Team December 23, 2016 01:48 PM UTC

Hi Samuel,

We regret for the lack of communication in our previous updates.

Yes, DocIO MailMerge functionality will meet your requirement perfectly (if you have field values (data) for Mail merging). Executing mail merge using DocIO, will internally replaces the merge fields with its respective value and preserves only static text in the resultant document. So, by using DocIO you won’t need “the highlighted brown lines”, which you used to find merge field names, its corresponding values and remove the merge fields from the document.

Please refer the code example from below UG link to achieve your requirement using DocIO:
https://help.syncfusion.com/file-formats/docio/working-with-mailmerge#simple-mail-merge

The resultant document will have only the static text and no information about the merge fields.

From your question “I found if I use: document.MailMerge.Execute(fieldNames, fieldValues), it can do what we want. But again, I need the list of values”. We have few doubts regarding your requirements.
1. What is the type of data source you have used for mail merging? Like database, business objects, string array, etc.

On analysing your code snippet, we have some more doubts.
1. How the Microsoft Word document template (Used as input file for mail merging) is created?
2. Usually in Microsoft Word document when a merge field is created with name “AAA”, the default field result will be updated as “<<AAA>>”. Retrieving the merge field name and result using any Word processing component will return “AAA” and “<<AAA>>” respectively. Please elaborate us about how the merge field name and result will be preserved in your Word document template (Used as input file for mail merging).

We also suspect you didn’t use any data source for mail merging, instead you might be replacing merge field with its default result as static text (For this purpose you are using Mail merge functionality of another commercial API). Could you please provide the requested details? So, that we can provide you exact solution at the earliest.

Please let us know if you have any other questions.


Thanks
Sivasubramani.



Loader.
Live Chat Icon For mobile
Up arrow icon