This documentation is archived and is not being maintained.

Document Serialization Sample

The Document Serialize sample shows how to serialize a document to an external file in one of several popular formats: flow document XAML, HTML, RTF, plain text, WordXML, or XPS.

When the application starts, selecting "File | Open..." displays the "Open Flow Document" dialog that allows you to choose a XAML flow document that you wish to open (several .xaml flow documents are provided in the sample \Content folder). Once a document is selected, click "Open" to display the document in the FlowDocumentPageViewer control located in the main application main window. A series of tabs, "Pages", "Bookmarks", and "Comments", are displayed to the left of the page viewer control, along with a column of figures based on the current tab selection. After selecting some text within the document, you can right-click to display a context menu that allows you to add either a "Bookmark" or "Comment" note. A "Bookmark" appears as a highlight on the text while "Comment" notes display a StickyNoteControl where you can type and add your own notes. The "Pages", "Bookmarks", and "Comments" tabs along the left edge of the application window control the type of thumbnail selections that are displayed: either document pages, bookmarks, or comment notes. Clicking a thumbnail positions the associated content to display in the page viewer control.

Once a document is opened the "File | Save As..." menu option is enabled. Clicking "File | Save As..." opens the "Save As" dialog for outputting the document content to disk. Within the "Save As..." dialog, the "Save as type" selection allows you to choose one of six serialization formats:

  • Flow document XAML (.xaml)

  • HTML document (.html or .htm)

  • Rich Text Format (RTF) document (.rtf)

  • Plain text (.txt)

  • WordXML document (.xml)

  • XML Paper Specification (XPS) document (.xps)

Specifying a file name and then clicking "Save" executes the serialization operation that stores the document to disk in the selected format.

This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Security - Windows Presentation Foundation Security

Localization - WPF Globalization and Localization Overview

Download sample

  • Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  • Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  • To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  • To build the sample in Microsoft Visual Studio, load the sample solution or project file and then press CTRL+SHIFT+B.

  • To run the compiled sample from the build environment command window, execute the .exe file in the Bin\Debug or Bin\Release folder contained under the sample source code folder.

  • To run the compiled sample with debugging in Visual Studio, press F5.