views:

1721

answers:

2

I'm looking for some suggestions on how to go about this. Any input is appreciated!

Currently, I have an ASP.NET MVC application. On the client, I have a link with an ID of an XPS document. When the user clicks the link, they are taken to a page with details about the document. In addition to this information, I wish to display the document along side of this information, in the same page.

On the server side, once I have the ID, I can get the document, serialized as a byte array, from the database. The question is, what's the best way to get that serialized document into the webpage?

I would SEVERELY prefer not having to drop that document into the file system and then munge together a file path. I would like to be able to stream the document to the browser as a content type of "application/vnd.ms-xpsdocument".

I've tried using a web control to handle this (can't write binary out), thought about creating a HTTP handler to do this (no idea where to start), and have fuddled around with a couple other ways to get the document stream to the browser.

In addition, there is also the question of how to embed the document in the web page. Do I use an EMBED tag? Or an Object? Or do I use an iframe and set the source to point to whatever delivers the document?

Again, I don't expect a solution wrapped up in a bow. I'm looking for some advice on how to go about this. And, while this question is about xps documents, it applies to any application that streams a binary file that is to be hosted in a browser (PDFs, etc).


Okay, as for displaying in the browser, one word: Silverlight. That's solved. I still have the issue of figuring out the best way to send it from the server to the browser.


Strike that. It appears Silverlight isn't advanced enough to display an XPS document just quite yet. I'm thinking about an iframe pointing to a http handler now... The iframe works. Too bad it throws the entire thing down the pipe. I suppose I could always strip off the first page and send that puppy...


Wow. No need for a HTTP handler. A custom ActionResult in MVC is all you need. How friggen awesome is that?

+2  A: 

I think the simplest way would be to provide the document as a link (target="_blank") from the details page. This has several advantages:

  • You don't need to retrieve and stream the entire doc unless the user asks for it.
  • On my system at least IE is already registered as the default XPS viewer, so by giving the doc it's own window you avoid the whole question of how to embed it.
  • It makes it simple to provide a streaming source for the document: just use an HTTP Handler with an ID for a query string parameter.

Even if you don't like that idea, definitely go with an HTTP Handler for transmitting document. It's real simple to do: when you create a new HTTP Handler in Visual Studio it should give you a nice page with all the busy-work done already.

Joel Coehoorn
If done right, I don't have to stream the entire thing because XPS documents are built to deliver their content on demand. The document contains individual packages that are managed by a package store. Individual packages are delivered when needed. Its pretty sweet.
Will
Hey, me, its too bad that won't work. Silverlight isn't mature enough yet.
Will
A: 

There is a Silverlight control capable of displaying XPS documents. See http://firstfloorsoftware.com/blog/announcement-document-toolkit-for-silverlight/ for more