RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Using OPC to Store Your Own Data : Page 3

Office Open XML uses OPC to store documents. Here's how to use packages for your own purposes.


Putting it All Together

You've seen most of the fundamental operations required to store data in an OPC package. To demonstrate how all this code hooks together, the sample code for this article combines all the code you've seen so far with a simple user interface (see Figure 4) that lets you create or open an album, and add and remove pictures.

Figure 4. Explore OPC: This sample application illustrates the principles of storing, associating, and retrieving information from OPC.

OPC Recommendations

Although you've seen how to perform the individual operations required to work with OPC, when you're building a real-world application, you'll want to follow these recommendations:

  • Chunk data: You probably noticed that the article example associated a separate XML file with each image rather than creating one big XML file for the entire album. One advantage of this approach is that you won't lose all your data if the package somehow gets corrupted.
  • Use indirection: Rather than referencing stored data directly, you can use relationships to reference the same data from multiple parts. For example, if you use the same image 50 times in a Word document, you only need to store one copy of the image. This both reduces the amount of space necessary to store the document and allows you to replace that image in all 50 locations in your document with one operation.
You've seen that OPC can be used to store disparate data types in a single container. This approach has many advantages over using a directory of files including organization and portability. While OPC isn't a replacement for a full-blown database, it is a compelling choice to store many kinds of application data.

Rich Quackenbush is lead software engineer for Vitech Corporation. He has been developing software for 10 years and has worked on a broad range of products.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date