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
Try
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
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
Next
man.Save(man.OriginalFileName) ' save original document
End Sub
End Module