This project is read-only.

How to read an XPS file from outside the deployed XAP file

Feb 17, 2011 at 1:17 PM


For some reason I can't figure this out. Any pointers will be appreciated. It will be a newbie mistake, this is for sure.

What I'm trying to do is created a website where XPS documents can be uploaded and stored for viewing. It is to enable content updating, such as a newsletter for example, without the need to redeploy the XAP file.

I cannot figure out how to get the Document Toolkit control to load an XPS file from a folder on the webserver rather than from within the XAP file.

There is probably a really easy way to enable this and I'm missing the obvious. I'd appreciate someone gently pointing out where I'm going wrong!



Feb 17, 2011 at 6:51 PM

Hi Glyn,

You'll need to use a WebClient to download your documents and once succesfully downloaded you can use the response stream and feed it to a package reader. Something like this should work:


// load the entire XPS document in once using a WebClient

var webClient = new WebClient();

webClient.OpenReadCompleted += (o, e) => {
  if (e.Error != null)
    // TODO: show error
  else if (!e.Cancelled) {
    // create new package reader
    this.DataSource.PackageReader = new SharpZipPackageReader(e.Result);

// loads the sample XPS document from the web
webClient.OpenReadAsync([url to XPS document]));


Document Toolkit is able to load documents from any source (isolated storage, memory, the web, etc.). As long as you have a stream to a valid XPS, Document Toolkit should be able to render it.

See also the SampleBrowser source code and specifically the SampleBrowser\Views\LoadingStrategies sample.


Feb 17, 2011 at 7:24 PM

Hi Koen,

Thanks for the prompt response and example code.

Being a newbie I was making a silly mistake I think. I'd come up with much the same code and could not get it to work on my development machine using the Visual Studio Development Server. When I published the little test application to my test server it worked fine!

I must have my development environment and/or priject files configured incorrectly, but I'm not sure where I've gone wrong.

I assume I should be able to debug and deploy the same code and it work ok, so the fact that it works on the web server but not my development machine indicates a mistake on my part?

Many thanks for your help,




Feb 17, 2011 at 8:54 PM

Hi Glyn,

Maybe the url to the XPS document doesn't work in the dev environment? You can use an HTTP sniffer such as Fiddler to inspect network traffic.


Feb 17, 2011 at 9:42 PM

Hi Koen,

I fired up Fiddler which prompted me to download a newer version, so I did.

Now everything is working as I thought it should! :-)

I think I may have been a newbie victim of the browser cache, or a machine so full of installed and uninstalled bits and pieces and betas that perhaps something wasn't playing nicely. For whatever reason installing the new version of Fiddler had a very useful side-effect!

Anyhow, whatever it was it seems to have cleared up now, and I didn't even have to turn my machine off and on again ;-)

Thanks for your help.