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

Free Support Forum - aspose.com

Vb.net, aspose.Word script to append word documents in one folder to a target document in another folder. target document is modified and bigger but I don't see any pages

attempting to append documents from one folder into a document in a different folder.
Windows 10. Visual Basic 2019.
The time stamp and size of the target document are updated. But there is nothing in the document.

Imports System
Imports System.IO

Imports Aspose.Words
Imports Aspose.Words.Document

Module Program
    Dim hdir As String

    Dim man As Aspose.Words.Document 'target document
    Dim di As DirectoryInfo 'directory with files to append
    Dim fiAr() As FileInfo 'list of files to append
    Dim fina As FileInfo 'temporary document info to append to target document
    Dim dataDir As String 'name of directory of target document
    Dim tDoc As Document 'temporary document to append to target document
    Dim i As Integer = 0

    Sub Main(args As String())

        hdir = "F:\London Road milk convoy\" 'directory with files to append
        dataDir = "F:\New Folder\" 'directory with target file

        man = New Document(dataDir + "manuscript03252021.docx") 'create target document
        di = New DirectoryInfo(hdir)
        fiAr = di.GetFiles("docx") 'get list of files to append

        For Each fina In fiAr

                Console.WriteLine("fina name " + fina.Name)
                tDoc = New Document(hdir + fina.Name) 'create append document
            Catch ex As Exception
                Console.WriteLine("new document error " + fina.Name + ex.Message)
            End Try

                man.AppendDocument(tDoc, ImportFormatMode.KeepSourceFormatting) ' append document to target document

            Catch ex As Exception
                Console.WriteLine("error appending document " + fina.FullName + ex.Message)

            End Try

            i = i + 1

            If (i > 0) Then
                man.Sections(i).HeadersFooters.LinkToPrevious(False) 'unlink sections
            End If


        man.Save(man.OriginalFileName) ' save original document

    End Sub
End Module


Could you please ZIP and attach your input Word documents here for testing? We will investigate the issue and provide you more information on it.

Thank you.

London Road milk convoy.zip (41 KB)

New folder.zip (336 Bytes)


We have tested the scenario using the latest version of Aspose.Words for .NET 21.3 and have not found the shared issue. So, please use Aspose.Words for .NET 21.3. We have attached the output document with this post for your kind reference.

output.zip (8.7 KB)

What version of word did you use?


I am using MS Word 2016 (64 bit).