Caching Data in the Document

Caching data in the document enables you to access the data when the document is offline or when you want to persist data between sessions or make the data available on the server. An offline document is one that is not connected to the network. Data that you bind to controls can be cached in the document by adding the CachedAttribute to a dataset in your solution making it available when the document is offline.

Cached data is stored in the Runtime Storage Control, which is part of every Word and Excel solution created with VSTO. If you have a variable declared as a Dataset within your solution, you can add the following attribute to the left of the declaration to start the data caching:

<Microsoft.VisualStudio.Tools.Applications.Runtime.Cached()>

Alternatively, in the Properties window you can set the CacheInDocument property of the instance of the dataset to True. Because the dataset instance must be public, you should also change the Modifiers property from Internal to Public.

You can also programmatically add a data object to the document's data cache by calling the StartCaching method on the document and passing the dataset to be cached. You can stop caching the dataset by calling the StopCaching method. Using data caching in documents on a server is described in more detail in Chapter 13.

0 0

Post a comment