Importing and Coping - what is the difference.
What is the ImportSession.

Element instances from the one document cannot be inserted into another document instance. They must first be imported to another document, and after then you can insert them. The following example shows the importing process:

Complete code

using System;
using SautinSoft.Document;
using System.IO;
using System.Linq;
using System.Text;

namespace Sample
    class Sample
        static void Main(string[] args)

        /// <summary>
        /// Copy a document to other document. Supported any formats (PDF, DOCX, RTF, HTML).
        /// </summary>
        /// <remarks>
        /// Details:
        /// </remarks>
        static void ImportingElement()
            string file1 = @"..\..\..\digitalsignature.docx";
            string file2 = @"..\..\..\Parsing.docx";
            string resultFile = "Importing.docx";

            // Load files.
            DocumentCore dc = DocumentCore.Load(file1);
            DocumentCore dc1 = DocumentCore.Load(file2);

            // New Import Session to improve performance.
            var session = new ImportSession(dc1, dc);

            // Import all sections from source document.
            foreach (Section sourceSection in dc1.Sections)
                Section destinationSection = dc.Import(sourceSection, true, session);

            // Save the result.

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultFile) { UseShellExecute = true });


Option Infer On

Imports System
Imports SautinSoft.Document
Imports System.IO
Imports System.Linq
Imports System.Text
Module Sample
    Sub Main()
    End Sub

    ''' <summary>
    ''' Copy a document to other document. Supported any formats (PDF, DOCX, RTF, HTML).
    ''' </summary>
    ''' <remarks>
    ''' Details:
    ''' </remarks>
    Sub ImportingElement()
        Dim file1 As String = "..\..\..\digitalsignature.docx"
        Dim file2 As String = "..\..\..\Parsing.docx"
        Dim resultFile As String = "Importing.docx"

        ' Load files.
        Dim dc As DocumentCore = DocumentCore.Load(file1)
        Dim dc1 As DocumentCore = DocumentCore.Load(file2)

        ' New Import Session to improve performance.
        Dim session = New ImportSession(dc1, dc)

        ' Import all sections from source document.
        For Each sourceSection As Section In dc1.Sections
            Dim destinationSection As Section = dc.Import(sourceSection, True, session)
        Next sourceSection

        ' Save the result.

        ' Show the result.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultFile) With {.UseShellExecute = True})
    End Sub
End Module


If you need a new code example or have a question: email us at or ask at Online Chat (right-bottom corner of this page) or use the Form below:

Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.