Set Author Sample

A sample application that uses the Packaging APIs to read and modify an existing package.

This topic contains the following sections.

Description

A sample console application that demonstrates how to use the Packaging API in conjunction with MSXML to read and modify an Office Open XML word processing file, such as a Microsoft Word 2007 or a Windows WordPad document.

The sample demonstrates the following features:

  • Using the Packaging APIs in conjunction with MSXML.
  • Loading a package that is an Office Open XML word processing document.
  • Displaying some of the text in the document package.
  • Modifying core properties of the document package.
  • Saving the modified package as a new word processing document.

Requirements

Product Version
Microsoft Windows Software Development Kit (SDK) Windows 7
ATL .NET Framework

Downloading the Sample

This sample is available in the following locations:

Location Path/URL
Windows SDK \Program Files\Microsoft SDKs\Windows\v7.0\Samples\dataaccess\OPC
Code Gallery Download from MSDN Code Gallery

Building the Sample

The following procedure describes how to build the sample.

  1. Install the Microsoft Windows Software Development Kit (SDK).

  2. Register the Windows SDK.

  3. Follow steps for building, using Visual Studio or the command prompt.

    Using Visual Studio 2008:

    1. Open Windows Explorer.
    2. Navigate to the directory that contains the setauthor.sln file.
    3. Double-click the setauthor.sln file to open it with Visual Studio 2008.
    4. Go to the Build menu in Visual Studio and select Build Solution.

      Note

      If the sample does not build successfully, close Visual Studio 2008 and run the .NET Framework Configuration Tool (Mscorcfg.msc) before attempting to build the sample.

    Using the command prompt:

    1. Open the command prompt.
    2. Navigate to the directory that contains the "setauthor.vcproj" file.
    3. Enter the following command: msbuild setauthor.vcproj.

Either the Debug or Release build mode may be used.

Running the Sample

Before running the sample application, ensure that the sample project has been built in the Debug or Release mode that corresponds to the build mode that will be used to run the sample.

The following procedures describe how to run the sample using Visual Studio or the command prompt.

Using Visual Studio 2008:
  1. Open the Properties of the sample project.
  2. Under Configuration Properties, click the Debugging item.
  3. Type either of the following two sets of arguments into the Command Arguments text box and then click OK.
    • To view text and authorship information when the sample program runs, type: setauthor.exe sample.docx.
    • To view text and modify authorship information when the sample program runs, type: setauthor.exe sample.docx <NewAuthorName><NewDocumentName>.docx.
  4. Run the sample.

Using the command prompt:

  1. Open the command prompt.
  2. Navigate to the directory that contains either the \Debug or the \Release project directory, as determined by the mode used to build and run the sample.
  3. Run the sample by entering either of the following commands.
    • To view text and authorship information, enter: setauthor.exe sample.docx.
    • To view text and modify authorship information, enter: setauthor.exe sample.docx <NewAuthorName> <NewDocumentName>.docx.

Additional Information

The modifications made to the package can also been seen in the package file itself after the package has been saved. Rename the output file by adding a .zip extension, and browse the package. Navigate to the Core Properties part and open it with Notepad or Internet Explorer to view properties XML markup.

Sample Files

File Description
setauthor.sln Visual Studio 2008 solution file.
setauthor.vcproj Visual Studio 2008 project file.
setauthor.cpp Entry point for the sample.
wordlib.h Declarations of utility functions for Open Office XML word processing files.
wordlib.cpp Definitions of utility functions for Open Office XML word processing files.
opclib.h Declarations of utility functions for packages in general.
opclib.cpp Definitions of utility functions for packages in general.
util.h Helper definitions for using COM and ATL.
sample.docx An Office Open XML word processing document for use with the sample.