Another code release - Preview Handlers for XP
3/28/2008 10:03:23 PM
Almost a year ago I learned about preview handlers from an awesome article written by Stephen Toub. Preview Handlers are essentially the 'reading panes' for file types. Think about when you read an email message in your mail client (most of them have some type of reading pane now) as you highlight the message, you get a view next to (or under) of the message contents. Wouldn't it be nice if you could do this for your file explorer or for email attachments? Well, in Windows Vista, you can already. With Outlook 2007, you can also get that feature with email attachments. This feature of preview handlers is a part of those products. The best part is...it is extensible! There are included preview handlers for Office documents, but not for custom ones. After reading the article (and downloading the massive collection that Stephen did), I set out to create my own for PDFs as I wasn't an Acrobat Reader user, but rather a Foxit user. This resulted in the Foxit PDF Preview Handler. There was one caveat, however. You needed Vista.
You see, Vista includes the out-of-process host for previews (prevhost.exe) and because this is included, you can write your preview handlers in managed code. This is great for developers as you simply implement a few interfaces and go to town writing your C# or VB code to handle your custom .foo files or whatever you wanted. For Windows XP users though who wanted the same functionality for the custom file types (i.e., PDF, ZIP, etc.), the same installs would not work. This is because there is no preview host on XP. So to write a preview handler targeting XP, you'd first also have to write the preview host, an out-of-process COM server essentially.
That is where today's code release comes in. When the preview handler article was written, there was a little sidebar about this COM server situation for XP. It was mentioned, but no real implementation shown. Ryan Gregg, a program manager for the Outlook team, had written one for PDFs for Vista or XP and put it out there. He released the binary but not the source. And after Adobe implemented their own preview handler in Reader 8.1, he removed his download. Well, we're bringing it back!
Today we published an MSDN Code Gallery project called the Preview Handler COM Server. This code gallery sample includes the code Ryan used to create his handler. The code is a good demonstration of creating a COM server host in .NET, thanks to some helper code from CodeProject, as well as the necessary code required to implement the preview handler interfaces. In the video attached to this post, you'll see me take 4 minutes describing what amounts to the core piece of this code sample, demonstrating implementing a plain text handler using this code.
And since I got numerous requests for the Foxit handler for XP, you can download it now. It uses this same implementation and adds the funcionality of presenting a PDF using the Foxit ActiveX framework, without having to have any PDF reader installed on your machine. As a reminder this one is for XP and I recommend sticking with the managed handlers for Vista as it already has the preview host as a part of the operating system.
Hopefully this will get you started for developing preview handlers that target Outlook 2007 on Windows XP if that is a need for you!