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:

    Copy
    using (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 open Document objects before changing the session configuration.