Bookmarks disappearing when merging

I am trying to mass merge about 9.000 Word documents using Aspose.Words. In the header and footer of the document there are statements like this: { INCLUDETEXT “I:\MyFolder\logo.doc” MyBookmark }
Before merging the document has a “MyBookmark” and when manually merging, the “include-text” is correctly loaded. But when merging through Aspose, the bookmarks are removed in the completed document, and the “Include-text” is not loaded before merging. Is there any way to trigger the Include-text before the merge?

@tomddlc Could you please attach sample document and code here for testing? We will check the issue and provide you more information.
I have checked updating INCLUDETEXT field with a simple code example and it works fine on my side:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField("INCLUDETEXT \"C:\\\\Temp\\\\test.docx\" test");
doc.Save(@"C:\temp\out.docx");
doc.Save(@"C:\temp\out.pdf");

Hi Alexey,

I have attached the template, the data source and the logo-file I am trying to include.Test.zip (18.1 KB)

Thanks!

If you want to see the code I am using - here it is:

AsposeLicense := AsposeLicense.License;
AsposeLicense.SetLicense(LicensePath);
AsposeWrapper := AsposeWrapper.Wrapper;
AsposeDoc := AsposeWrapper.DocumentString(DataPath);

FullText := AsposeDoc.GetText;

SplitPos := STRPOS(FullText,'"');
Headers := COPYSTR(FullText,1,SplitPos-1);
MergeText := COPYSTR(FullText,SplitPos);

NetString := Headers;
Separator := ';';
TrimText := '"';

HeaderArray := NetString.Split(Separator.ToCharArray());
NetString := DELCHR(MergeText,'=','"');

DataArray := NetString.Split(Separator.ToCharArray());

AsposeEndDoc := AsposeWrapper.DocumentString(TemplatePath);
AsposeMailMerge := AsposeEndDoc.MailMerge;

AsposeDocBuilder := AsposeDocBuilder.DocumentBuilder;
AsposeDocBuilder.Document := AsposeEndDoc;
AsposeDocBuilder.InsertField(IncludeHeader);

AsposeMailMerge.Execute(HeaderArray,DataArray);
AsposeEndDoc.Save(EndPath);
MESSAGE('Complete');

@tomddlc Thank you for additional information. I have investigated your documents and as I can see in the header of your template there are fields like this:
{ INCLUDETEXT "I:\\Advoforum\\Skabelon\\Logo\\logo.doc" adv }
{ INCLUDETEXT "I:\\Advoforum\\Skabelon\\Logo\\logo.doc" adv2 }
but in the logo.doc file there are no bookmarks with adv and adv2 names. See the screenshot:

INCLUDETEXT fields in your template are already updated and if you need to preserve the values, which are already in the template you have two options:

  1. Lock the INCLUDETEXT fields. In this case Aspose.Words will ignore the locked fields upon field updating. See the following code:
For Each f As Field In doc.Range.Fields
    If f.Start.FieldType = FieldType.FieldIncludeText Then
        f.IsLocked = True
    End If
Next
  1. Unlink the INCLUDETEXT fields. In this case the fields will be replaced with their values. See the following code:
For Each f As Field In doc.Range.Fields
    If f.Start.FieldType = FieldType.FieldIncludeText Then
        f.Unlink()
    End If
Next

Again you are my saviour Alexey - the last tip about unlinking works perfect :slight_smile:

You can close the issue

Thanks!