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

Free Support Forum - aspose.com

List.Id

I am using Aspose.Words to generate a bunch of Documents that are consumed by another application.

The problem I am running into is that I can’t control the ListId. Each new document I create starts the list id at 1. The problem is when these documents are subsequently consumed, Word thinks that all these lists are the same list, since they all use the same id. This means that the same style is applied to them and the numbering is continuous throughout the document, instead of restarting.

Is there any way to control the ListId? It appears to be a read-only property and I haven’t found a constructor to control its value.

It is alright for different documents to have non-unique list ids. In fact, in all MS Word documents created by MS Word from scratch list id start at 1. Therefore Aspose.Words does the same.

There is a bit of a problem when merging such documents together or copying paragraphs from one to another. Some (sometimes substantial) logic is needed to correctly resolve (import) lists from one document into another. Both MS Word and Aspose.Words do this very well. E.g. if you properly merge two documents that both have list id 1 then you end up with a document with two different lists.

I think the problem in your case lies in "another application" that does not correctly merge lists. Can you tell me more about it.

There is no way in Aspose.Words to change list id because we consider it to be too "low level" concept and therefore Aspose.Words take care of it automatically.

Maybe you should just use ASpose.Words to merge documents instead of the other application. See Document.AppendDocument, Document.ImportNode, NodeImporter for more info.

The other application creates a master document and gets Word to merge/include the documents using the INCLUDETEXT field.

At this point in time, moving away from the master application that creates this master document is infeasible. We are migrating to Aspose.Word in a piecemeal fashion, but that process is scheduled to take years.

Since I can’t programmatically change the list id, I employed the following hack:

docBuilder.Document.Save(docFilename, SaveFormat.Rtf);

//get the contents of the rtf file
string contents;
using (StreamReader reader = new StreamReader(docFilename))
{
contents = reader.ReadToEnd();
}

//generate a new list id
int listId = this.randomNumberGenerator.Next();

//adjust the rtf file so that it uses this new list id
string newListId = String.Format("\listid{0}", listId.ToString(NumberFormatInfo.InvariantInfo));
contents = contents.Replace("\listid1", newListId);
Debug.WriteLine(newListId);

//save over the original rtf
using (StreamWriter writer = new StreamWriter(docFilename, false))
{
writer.Write(contents);
}