×

First time here?

You are looking at the most recent posts. You may also want to check out older archives. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS or email. Thank you for visiting!

(long, informative post with images -- apologies aggregates...click on the link :-))

in outlook 2007, when you have an attachement in a mail message and click on the attachment file, you are presented with an option to preview this attachment directly in outlook...just like the preview pane for a normal message:

previewmode

likewise in vista's file explorers, you can enable a preview pane and get the same functionality for highlighting a file in explorer as seen here:

previewvista

for productivity, namely in outlook 2007 for me, this is a great advancement to the platform.  i now don't have to double-click a file, etc and launch another program to see what usually is just a glance that is required.  this preview mode in the file explorer has existing in windows xp, but was little used by developers.  this is likely due to the warnings and caution from microsoft to not use managed code for this feature.  in winxp, this functionality is executed in process, thus making it a dangerous path when multiple versions of the CLR might be invovled.

in vista, this is much more simplified and the model has changed to out of process...finally making it easier to do these things in managed code.  has an excellent article in the january edition of msdn magazine that covers this entire story and the in's and out's of preview handler development.  the great thing about his article aside from the depth of understanding you will gain is that stephen has created a managed interface to make it easier to implement your own preview handler.  you can download his code from the msdn preview handler code link here.  stephen encourages us to write our own preview handlers, but he's gone and done most of the ones i think we all use -- zip, xml, xaml, resx, csv, msi, internet explorer, etc.  they are all awesome.  the zip preview handler is especially cool since it also implements a treeview representation of the contents of the zip file...look at this sample showing the vista preview, but would be the same in outlook 2007 (note: this zip one also handles .gadget files):

zippvwhandler

one handler that stephen also provides is a pdf preview handler (probably the second one i will use the most next to the zip one).  in his sample, he uses the adobe activex control for the acrobat reader implementation.  now this would require that you have adobe reader installed.  if you are a frequent reader, you may know that i'm not a fan of adobe reader.  i use foxit reader from .  it's lean and mean.  i wanted to ensure i could still use the pdf preview handler, but had to modify a few things.

first i had to get the foxit activex sdk from their site.  there is a license cost to use this, which i'm currently investigating.  after getting the activex control, i modified stephen's code at about line 41 of of the PdfPreviewHandler.cs file in the download.  i changed it to:

// Foxit Reader ActiveX
public PdfAxHost()
    : base("d46a7492-4b6c-446f-8100-4812edf406c9") { }
 

then, i also had to change the pinvoke method.  the adobe control uses a LoadFile() signature, but foxit uses an OpenFile() signature.  foxit also uses a second parameter, the starting page of the document.  so i changed it to this code:

_ocx.GetType().InvokeMember(
  "OpenFile", BindingFlags.InvokeMethod, null, // changed to OpenFile
   _ocx, new object[] { fileName, 0 }, CultureInfo.InvariantCulture); // added 0 parameter to array
 

compiled and deployed...now i have pdf previewing in outlook 2007:

foxitpreview

it's a beautiful thing.  please check out stephen's article in msdn magazine -- it was a great read and well done -- i totally understood the concepts presented and it allowed me to create a few handlers of my own.  as a developer i frequently get code files sent as attachments.  i generally have to open them up and look at them in visual studio or notepad2 for code highlighting, etc.  well, with my new found knowledge i created a code preview handler.  it will see .cs, .vb, .js and .sql files and enable a previewer to show them in code-highlighted formatting in the preview window of outlook 2007 or windows vista explorer.  here's a sample:

codeprievewer

how is this accomplished?  well, aside from the great library stephen provided, i pulled together the HtmlApp code that nikhilk wrote, as well as the csharpformat from manoli and bundled them together to produce this.  i had some issues with manoli's library when trying to set the embed stylesheet property, but i just embedded it as a resource and that was fine by me.  it was easy to implement and here is the magical function code:

public override void Load(FileInfo file)
{
    StreamReader rdr = file.OpenText();
    string previewCode = rdr.ReadToEnd();
    string formattedCode = FormatCode(previewCode, file.Extension);

    HtmlApp.Html.HtmlControl html = new HtmlApp.Html.HtmlControl();
    html.LoadHtml(string.Format("<html><head><style type=\"text/css\">{0}</style><body>{1}</body></html>", SmilingGoat.PreviewHandlers.Properties.Resources.CssString, formattedCode));
    html.Dock = DockStyle.Fill;

    Controls.Add(html);
}


after this (the FormatCode funciton basically just does a switch on the file type and applies the appropriate formatting from manoli's object), the formatted code is rendered to view like the sample above.  it's really easy to implement.

one thing important to note about preview handlers is the fact that only one preview handler can be associated with one file extension and class.  what does that mean? well, simple...for example, you can't have two pdf preview handlers.  well what happens if i install two of them? last one will likely win -- depending on how it is registering itself.  you see, there will only be one registry entry for that file type, so the second one you install will overwrite the settings from the first one.  stephen planned on posting a little utility to see what preview handlers are registered for your machine...check it out to see how things are registering and to actually add additional ones.  for example, if i didn't want code highlighting, i could have easily set the TXT preview handler to also preview the code files mentioned above.  here are the links to my code preview handler:

File iconCode Preview Handler [source]
File iconCode Preview Handler Setup [MSI]


12/14/2006 12:37 PM | # re: vista and office dev: creating preview handlers
Nice handlers, Tim! I've put up the tool you mentioned at http://blogs.msdn.com/toub/archive/2006/12/14/preview-handler-association-editor.aspx
1/29/2007 4:59 PM | # re: vista and office dev: creating preview handlers
Hi:
I would like to create previewer for PDF files but am not a programmer. I installed Visual J# v2.0 but in attempting to install your MSI installer version I get the following error: Unable to get installer types in the C:...\codepreviewhandler.dll assembly. Unable to load one or more of the requested types. Can you give me any advice please.

Also do I need to download anything from foxit?

1/29/2007 10:05 PM | # re: vista and office dev: creating preview handlers
fred: ensure you have the .NET framework version 2 installed as well (should be there). send me the full error offline and i'll see -- i've not seen this reported before.

regarding the pdf one...i am awaiting an updated control from foxit.
1/30/2007 12:25 PM | # re: vista and office dev: creating preview handlers
Tim:
The only thing I didn't include from the message was: Retrieve the LoaderExcceptions property for more information. I do have .NET v2.0 & Visual J# 2.0 installed. With regard to pdf one, do you expect Foxit will comply? Thanks, Fred
1/31/2007 8:43 AM | # re: vista and office dev: creating preview handlers
fred: yes, i'm actually partnering with foxit to create it.
2/12/2007 3:09 PM | # re: vista and office dev: creating preview handlers
great post!! i wanted to make the same reader; i'd love to know when you/foxit release the extension!
2/17/2007 9:04 PM | # re: vista and office dev: creating preview handlers
JackO: the MSDN PDF preview handler requires you to have the Adobe Acrobat Reader installed -- i am DAYS away from releasing one that does not --
3/2/2007 4:50 PM | # re: vista and office dev: creating preview handlers
Hi Tim,

I'm trying to make a previewer to run in Outlook 2007, but without Vista. Do you have any ideas how to do that?

TIA
Gravatar
3/5/2007 6:56 AM | # preview handlers in XP?
hi,may i know if the File Preview Handler Setup [MSI] can be used in XP? Apparently, I have went ahead with the installation but no preview in outlook 2007 for pdf and html. thanks in advance!
3/26/2007 4:39 PM | # re: vista and office dev: creating preview handlers
I get the same error as Jon Galloway, error code 2869. Any idea what is causing this or how to fix it?
4/4/2007 10:23 AM | # re: vista and office dev: creating preview handlers
nope.. same error here.
4/4/2007 10:32 AM | # re: vista and office dev: creating preview handlers
if you are installing on Vista with user account control enabled, oyu have to elevate to a command prompt and then run msiexe /i <pathtoMSI>

i did change the MSI installer so it should prompt automatically, so you may want to re-download and try both methods.
5/19/2007 3:22 PM | # re: vista and office dev: creating preview handlers
Hi,
I've created a bunch of preview handlers, including those displayed here (I used Acrobat instead of Foxit), and put them (and their source code) in here:
http://www.azarfamily.org/previewhandlersforwindowsxp

Enjoy :)
5/29/2007 4:07 AM | # re: vista and office dev: creating preview handlers
Is it possible to view the preview of files in a custom application in Vista.
Not in the expolorer
6/7/2007 8:04 PM | # re: vista and office dev: creating preview handlers
ok
12/14/2008 8:35 PM | # re: vista and office dev: creating preview handlers

Looking for preview handler for .rar files? Thanks to the MSDN preview pack, I've got everything else covered EXCEPT .rar files...
1/26/2009 1:24 AM | # re: vista and office dev: creating preview handlers
Is it possible to preview office documents and highlight specific words?
Plus, i am looking for a preview for simple text files and eml (outlook express) files (container files)
1/26/2009 3:08 PM | # re: vista and office dev: creating preview handlers
Yaniv by default simple text files (txt) should use the default preview handlers provided by Office 2007. As far as previewing documents and highlighting specific words, I'm sure someone could develop this, but how would it know which words to highlight?
6/17/2009 9:40 PM | # re: vista and office dev: creating preview handlers
I am using window XP sp2, office XP (not 2007) & outlook 2007. Is it still possible to preview office documents (like .doc, .xls, .ppt etc) in outlook then ? Thanks for any comment in advance !
6/17/2009 9:47 PM | # re: vista and office dev: creating preview handlers
Toad -- you state office xp, but outlook 2007...I'm confused...which is it? If you have Outlook 2007, you can use preview handlers, but the doc/xls/etc. may not be built in...you can check.
6/18/2009 3:12 AM | # re: vista and office dev: creating preview handlers
Thanks for ur reply Tim. I installed office XP but separately installed outlook 2007 only. I checked there's no preview handler for doc/xls etc. So do I have to install the full pack of office 2007 (not just outlook) ?
6/18/2009 8:06 AM | # re: vista and office dev: creating preview handlers
Toad -- Probably so. Honestly I'm not sure where the office handlers come from, but that's reasonable to suspect they are from the full Office 2007 install.
8/12/2009 10:39 PM | # re: vista and office dev: creating preview handlers
Tim, I tried to download your Preview Handler [source]
& Preview Handler Setup [MSI] from the box.net you mentioned but after i tried several times what my Mozilla Firefox found is :

Address Not Found
www.box.net could not be found. Please check the name and try again.

I'm connected to the Internet, but not able to find the domain.
does the domain still exist?
I am expecting for your reply, or if you do not mind, please send me the file to my email. Thanks.
10/10/2009 4:09 PM | # code previewers working in Vista Explorer Preview pane, but not Outlook 2007
Tim,
I know you probably haven't done much with these lately, but I was wondering if this problem was just mine or if, perhaps, something had changed in Outlook (SP1 or SP2?).

I have a few preview handlers installed, including your Code Preview Handler pack. For example, I can preview .js files in Vista's explorer preview pane, but in Outlook 2007, it says "This file cannot be previewed. Try opening the file in the program in which it was created."

I'm running Vista Ultimate SP2 and MS Office Enterprise 2007: Outlook (12.0.6504.5000) SP2 MSO (12.0.6425.1000)

When I use either PreviewConfig (by Ramesh Srinivasan), Preview Handler Association Editor (by Stephen Toub), or Outlook's Trust Center > Attachment Handling > Attachment and Document Previewers tool, they show that your "Source Code Preview Handler" (PreviewConfig shows it as TimHeuer.PreviewHandlers.CodePreviewHandler) is associated with .cs, .js, .sql, .vb.

Any idea why it would work in Vista's explorer preview pane and not Outlook's preview pane?

Thanks!
10/16/2009 3:03 PM | # re: vista and office dev: creating preview handlers
David -- sorry, I'm not sure what could be causing that. It's the same mechanism for previewing on Vista. Sometimes, the file extensions are prevented in some Outlook configurations (i.e., we don't allow js attachments)
Gravatar
1/8/2010 1:55 PM | # mediaplayer auto view in 200% zoom
Where can I setup the media player to automatically open the video in 200% zoom ?
1/10/2010 2:42 AM | # re: vista and office dev: creating preview handlers
I got some problems with preview outlook 2007 before Vista OS ,can you come out with solution soon?
1/27/2010 9:55 AM | # Broken in XP?
Like some others, I can't get the basic MSDN previewers or this code previewer to work in XP using Office 2007. The Office (Word, etc.) previewers work, but not these. Any suggestions for XP users (besides upgrading)?
4/29/2010 1:32 PM | # re: vista and office dev: creating preview handlers
I noticed that this only works for files whose extension is in lower case (".sql" not ".SQL" or ".Sql"). A simple fix would be to change line:45 in CodePreviewHandler.cs from

switch (codeType)

to

switch (codeType.ToLower())

Other than that, awesome app you've got here!
4/29/2010 1:59 PM | # re: vista and office dev: creating preview handlers
'nother area for improvement that I noticed with regards to capitalization of extensions. If the file cannot be previewed due to capitalization (extension is ".SQL" not ".sql") then the lock against the file is not released.

To reproduce:
• Click a SQL file with an extension of ".Sql," notice that the previewer does not open.
• With the file still selected, open it in your IDE of choice.
• Make a trivial modification.
• Save.
• Receive error akin to "The operation could not be completed. The process cannot access the file because it is being used by another process."

After a 30 second glance through the code, there was nothing jumping out at me that would cause this. But perhaps this would resolve itself by implementing my previous suggestion.

Code away!
7/22/2010 7:11 AM | # re: vista and office dev: creating preview handlers
Hi,

is there a way how to implement these handlers to a Windows form of my own? For example I want to create a simple form with ListView to view some files and a some control where do I want to display a preview.
Is that even possible?

11/26/2010 3:28 AM | # re: vista and office dev: creating preview handlers
Hello!

I'm trying to understand the work of Preview Handlers and write my own.
In my Preview Handler I need to create temporary files and folders.
When I run my Preview Handler in Outllok 2007, anything works fine.
But when trying to view in Windows Explorer preview pane (I use Windows 7) the system returns "Error 5: Access denied" when it tries to create file or folder.
(I want to create files in the temporary folder of the current user.)

But, if there is MS Office installed I can view its documents as a preview in Windows Explorer.
The content of MS Office document (for example .docx) is unpacked to the Temporary Internet Files folder of current user when I preview it (I tried to put my temp files there also).
That is MS Office Preview Handler can create temporary files.

Please tell me do you know what I need to do to create temporary files or folders.
I use c++ and do not use .Net
As the base for my Preview Handler I am using previewhandlers pack by Gil Azar, mentioned here.

Thank you for any comment in advance !
6/28/2011 2:06 AM | # re: vista and office dev: creating preview handlers
It's good tips which i have added in my skills. I personally like window vista because of its security features and interface.

Speakers | Amplifiers
9/7/2011 5:24 AM | # WPF File previewer
Hi,
I want a Previwer For WPF appliaction ,which can support MSOFFICE files and PDF files.i want this in WPF appliaction .

Could You Provide Me A sample.

Thanks in Advance..
5/15/2013 10:48 AM | # re: vista and office dev: creating preview handlers
The link to download the code preview handler is broken... where can I find it???

 
Please add 2 and 1 and type the answer here:

DISCLAIMER:

The opinions/content expressed on this blog are provided "ASIS" with no warranties and are my own personal opinions/content (unless otherwise noted) and do not represent my employer's view in any way.