Using Document Objects
This topic provides some additional guidance about using document objects in your code.
- A
Document
must be created and used on the same thread that created the parent session. -
Changing session configuration options can change the data that is returned by methods of a document object, even if you created the document object before changing the configuration.
Consider the following example. You have a document with embedded images but no subfiles and you run the following code:
Copyusing (Document myDoc = session.Open(inputFilePath))
{
myDoc.Subfiles().Count(); // Returns 0
session.Config().ExtractImages(true);
myDoc.Subfiles().Count(); // Returns 3
}This example shows that the
ExtractImages
session configuration option must not be changed while iterating over subfiles - because the list of subfiles would be invalidated. OpenText recommends disposing all objects created by openDocument
objects before changing the session configuration.