Inserting Or Appending Documents does not update StoreItemID property of each inserted document

I am using Aspose.Words version 16.8.0 and I am having an issue creating a document containing several documents. We are using the following code to build a single document from multiple documents. The resulting document is then stored into a SharePoint library, where the properties of the document are updated via a workflow that populated the document properties from a list.

The issue is, the documents contained within the larger document are not updated to have a matching "StoreItemID", so when the XML for the document is built, not all the documents within the single document have the matching "StoreItemID" and are not populated with the correct data. The document will create multiple XML item files (item#.xml and ItemProp#.xml) for each "StoreItemID" rather than a single XML item file set with the correct "StoreItemID" for the entire document.

This means that not all of the fields in the document have the correct connection (because of a different StoreItemID) and therefore the fields do not populate. We need to create a single document containing multiple documents with a single StoreItemID so that all of the document properties correctly populate with data.

If the file is built using Microsoft Word as an ActiveX object, the documents contained within the single document will all have the same "StoreItemID" corresponding to the correct XML file. The documents using the ActiveX object are inserted using the "InsertFile()" method.

I have attempted to solve this issue using "builder.Document.AppendDocument()" as well as "builder.InsertDocument()", neither of which have solved the issue.


Code:

class CreateDocument : IDisposable {

private Document doc;
private DocumentBuilder builder;
private static string commonTemplateDir = "C:\\Templates\\PacketTemplate.docm";
private string templatesForFileString { get; set; }
private string[] templatesForFile { get; set; }

public CreateDocument() {
SetLicense();
doc = new Document(commonTemplateDir);
builder = new DocumentBuilder(doc);

templatesForFileString = "lgl1009R,lgl1009,lgl1019";

SplitTemplatesForFile(templatesForFileString);

int templateNumber = 1;
foreach (string template in templatesForFile) {
InsertFile(template, templateNumber);
templateNumber++;
}

builder.Document.Save("C:\\Templates\\TestDoc.docm");
Dispose();
}

private void InsertFile(string templateName, int templateNumber) {
if (!String.IsNullOrWhiteSpace(templateName)) {
string file = GetFileLocation(templateName);
Document newDoc = new Document(file);
newDoc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;

if (templateNumber > 1) {
builder.Document.AppendDocument(newDoc, ImportFormatMode.KeepSourceFormatting);
} else {
builder.MoveToDocumentStart();
builder.InsertDocument(newDoc, ImportFormatMode.KeepSourceFormatting);
}
}
}

private string GetFileLocation(string templateName) {
return "C:\\Templates\\" + templateName + ".docx";
}

private void SplitTemplatesForFile(string templatesForFile) {
if (!String.IsNullOrEmpty(templatesForFile)) {
this.templatesForFile = templatesForFile.Split(',');
}
}

private void SetLicense() {
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense("Aspose.Total.lic");
}

public void Dispose() {
doc = null;
builder = null;
}
}
Hi Adam,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word documents.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

The requested files are attached.



- Adam Woods

Hi Adam,

Thanks for sharing the detail. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14184. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.