MikeC
MikeC

Reputation: 284

Loading FlowDocument.xaml that is part of my solution

I created a FlowDocument.xaml in my current WPF project. What i want to do is when the user clicks a button the XAML document will be loaded in the code behind, have some data on the document modified, and then print it out. The sticking point is i don't know how load the flow document so that i can modify it.

When I do:

FileStream fs = File.Open("FlowDocument.xaml", FileMode.Open)

It says that it can't find the file. The file is part of the project and I'm guessing it gets packaged with the rest of the project when compiled.

Any help is appreciated

Upvotes: 4

Views: 2280

Answers (2)

CodeNaked
CodeNaked

Reputation: 41393

Assuming it is configured to be a Resource, then you can load it like so:

FlowDocument doc= Application.LoadComponent(new Uri("/Path/FlowDocument.xaml", UriKind.RelativeOrAbsolute)) as FlowDocument;

Upvotes: 8

w4ik
w4ik

Reputation: 1276

This looks like it might be a path/relative path issue...just for testing purposes, try specifying the entire physical/absolute path in the File.Open statement...

You could also do

string path = Directory.GetCurrentDirectory();

to check to see what the current directory is and then make sure that the file FlowDocument.xaml is in that directory

Upvotes: 0

Related Questions