PDI Preview Handler

Blog Post created by andreas on Jan 14, 2010

Preview Handler


The Preview Handlers have been introduced with Microsoft Windows Vista and with Microsoft Office 2007.
However, if you try to preview an attached PDI in Microsoft Outlook, you will see something similar to that:




When getting Windows 7 on my Notebook recently, Steve gave me a head's up to try and write a preview handler for PDI's.


A good start are this article of Stephen Toub, Managed Preview Handlers for Vista and Office in Daniel Moth's blog, More Preview Handlers from the same Blog and especially the screencast by Daniel Moth on channel9.


So what do you need (beside taking a look at the above resources)?

  1. Microsoft Windows Vista or Microsoft Windows 7
  2. Microsoft Visual Studio 2008
  3. The Managed Preview Handler Framework from here.
  4. OSIsoft PI ProcessBook 3.x or newer
  5. Microsoft Outlook 2007

The Code

And here is my Hello PI preview handler ;-)

  1. Download the msdn magazine preview handler framework from the first link.
  2. To build MsdnMagPreviewHandlers.dll, you might have as well to install the Microsoft Visual J# Redistributable Package
  3. As in Daniel Moth's example, create a new class library.
  4. Reference the MsdnMagPreviewHandlers.dll.
  5. Add a reference to System.Windows.Forms.
  6. Sign the assembly with a strong name key file.
  7. To render a PDI file we will need an ActiveX control. Hence we are here in .NET we need to create a managed wrapper for the PI ProcessBook Display Control. So we are going to create that wrapper with AxImp.exe:

  8. AxImp.exe





  9. We will have to add a reference to our AxPBDCtrl.dll.
  10. The code for the preview handler is below:

  11. using System;


    using System.Collections.Generic;


    using System.Linq;


    using System.Text;


    using MsdnMag;


    using System.Runtime.InteropServices;


    using System.IO;


    using System.Windows.Forms;




    namespace OSIsoftvCampusPreviewHandler




        [PreviewHandler("OSIsoft vCampus Preview handler",














        publicsealedclassOSIsoftvCampusPDIPreviewHandler : FileBasedPreviewHandler




            protectedoverridePreviewHandlerControl CreatePreviewHandlerControl()










            privatesealedclassOSIsoftvCampusPDIPreviewHandlerControl :






                publicoverridevoid Load(FileInfo file)




                    AxHost _pbDisplay = new AxPBDCtrl.AxPbd();




                    IntPtr forceCreation = _pbDisplay.Handle;


                    _pbDisplay.Dock = DockStyle.Fill;




                    AxPBDCtrl.AxPbd _AxPbd = (AxPBDCtrl.AxPbd)_pbDisplay;


                    _AxPbd.DisplayURL = file.ToString();









  12. After building the dll, we have to move it to the Global Assembly Cache (GAC) and register it:

  13. GACUTIL.EXE -i MsdnMagPreviewHandlers.dll


    GACUTIL.EXE -i OSIsoftvCampusPreviewHandler.dll


    GACUTIL.EXE -i AxPBDCtrl.dll


    GACUTIL.EXE -i PBDCtrl.dll


    REGASM.EXE /codebase MsdnMagPreviewHandlers.dll


    REGASM.EXE /codebase OSIsoftvCampusPreviewHandler.dll


    REGASM.EXE /codebase AxPBDCtrl.dll


    REGASM.EXE /codebase PBDCtrl.dll

The result is a PI ProcessBook Display preview handler that allows you to preview a PDI in Outlook




or Windows Explorer



  1. In this example we are using PI ProcessBook. However, all of this is possible with PI ActiveView as well (Note that PI ActiveView is not part of the OSIsoft vCampus PI Products Kit).
    PI ActiveView provides a means to view and interact with PI ProcessBook displays outside of PI ProcessBook. By embedding the PI ActiveView ActiveX control in other applications, such as Internet Explorer, and installing the local executable, users can view PI ProcessBook PDI display files without modification.
  2. This PreviewHandler uses the PI ProcessBook Display control to preview a PDI. Therefore it has the same requirements as PI ProcessBook: you need to have a PI SDK connection to the PI Server and the necessary access rights to view the data.
  3. The two batch files to register and unregister as well as the source code above can be downloaded here.

Call for Help

The community is explicitly invited to improve/extend my code. As an example - a known limitation is that the preview handler does not scale the display according to the visible area in the preview.