Share via


Data in Document-Level Customizations

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

Microsoft Office version

  • 2007 Microsoft Office system

  • Microsoft Office 2003

For more information, see Features Available by Application and Project Type.

Microsoft Office documents are often used as repositories of data. In the past, this meant that you had to start the Office application to be able to get to the data. However, in document-level customizations for Microsoft Office Word or Microsoft Office Excel, data can be stored in an embedded data island that is accessible without starting Excel or Word.

Separating the Data and the Document

A data island is an XML document containing data that is embedded in the Office document; the XML document can be accessed without running the Office application. The data actually exists in two places—in the document and also in the separate embedded data island. Data binding is used between the data island and the document to keep them synchronized. If code that runs on the server modifies the data island, the Office document will be synchronized to the data island when the document is opened and the code behind the document runs.

This model offers several benefits:

  • Schema-oriented programming

  • Data caching

  • Server-side data access

Schema-Oriented Programming

Visual Studio Tools for Office uses typed data sets to provide a schema-oriented programming model for interacting with the data island. This enables you to add validation code to the data that is independent of the document. Separating the validation from the document makes the data validation code portable to other documents.

Data Caching

The data island is filled with data that can be used offline. When a cached data item in the document contains data, the document interacts with the data island. Data sources that are declared using the CachedAttribute attribute are persisted in the data island. For more information, see Caching Data and How to: Cache Data for Use Offline or on a Server.

Server-Side Data Access

The fact that the data island is externally accessible means that you can modify the data embedded in a document without starting Office, which enables fast batch processing of documents on the server. Note that only data that is in the cache is accessible, not all data in the document.

Filling a Document on the Server without Starting the Office Application

The data island embedded in the document can be filled on the server without starting the Office application. You create a document and associate the schema of the data with that document. The document is then stored on the server. Your server-side code, for example code behind an ASP.NET page, calls methods in the Visual Studio Tools for Office runtime to fill the data island. For more information, see Accessing Data in Documents on the Server.

Exposing Data Embedded in a Document to ASP.NET Server Pages without Starting the Office Application

You can expose the data by creating a document and associating a data schema with that document. The document is then stored on the server. Code in an ASP.NET page can treat the document as a data source and can read and modify the embedded data island. Visual Studio Tools for Office provides components that can read the data island from a document, expose it to an ASP.NET page as a data source, and allow read and write access to the data. For more information, see How to: Retrieve Cached Data from a Workbook on a Server.

Editing a Document Offline

After the data island is filled from a connection to the server, the document can be used in a disconnected scenario such as traveling on an aircraft that does not have network connectivity. The data in the data island is available and can be manipulated even though there is no live connection to the server. Changes made to the data island can be propagated back to a server data source after a connection is available. For more information, see Saving Data Overview and How to: Update a Data Source with Data from a Host Control.

Data Security

If your solution connects to an external data source such as a database, Web service, or other server application, validate all input at the data source in addition to on the client. Even data that is cached in the document might not be what you expect it to be, as it is accessible from outside the document. For the same reason, do not include data in the cache that you do not want users to see.

For guidelines around secure data handling, see Security and User Input and Secure Client Applications (ADO.NET).

See Also

Concepts

Binding Data to Controls in Office Solutions

Caching Data

Accessing Data in Documents on the Server

XML Schemas and Data (Visual Studio Tools for Office)

Data Model in Document-Level Customizations

Other Resources

Data in Office Solutions