Downloading FlowDocument.xaml, which is part of my solution

I created FlowDocument.xaml in my current WPF project. What I want to do is when the user clicks the button, the XAML document will be loaded into the code behind, some data about the document will be changed, and then printed. I don't know how to load a stream document so that I can change it.

When I do this:

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

It says that he cannot find the file. The file is part of the project, and I assume that it will be packaged along with the rest of the project at compilation.

Any help is appreciated

+4
source share
2 answers

Assuming it is configured as a resource, you can load it like this:

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

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

You can also do

 string path = Directory.GetCurrentDirectory(); 

to find out what the current directory is, and then make sure the FlowDocument.xaml file is in this directory

0
source

All Articles