Confessions of a .NET Developer!

FlowDocuments in WPF – Part 3

In this small post, I shall explain how to save and load the flow documents that you have created. For this, there are two classes, XamlWriter and XamlReader.
You can read more about XamlReader and XamlWriter here :
and respectively.

Create two buttons(btnSave to Save and btnOpen to Open a flowdocument) and add a FlowDocumentReader to your WPF application.

In the save button, use FileStream to create a .xaml file and save the document there.

        private void btnSave_Click(object sender, RoutedEventArgs e)
            using (FileStream fs = File.Open(@"C:\Save.xaml", FileMode.Create))
                XamlWriter.Save(flowDocumentReader1.Document, fs);

Load the document from a location :

            using (FileStream fs = File.OpenRead(@"C:\Open.xaml"))
                FlowDocument document = (FlowDocument)XamlReader.Load(fs);
                flowDocumentReader1.Document = document;

Thats it, nothing much complicated here. Good luck!


May 1, 2011 - Posted by | WPF

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: