private void PreView( Guid guid, string fileName )
{
var encoding = new UTF8Encoding();
webBrowser.Visible = false;
sourcePreviewer.Visible = false;
var fi = new FileInfo( fileName );
if (fi.Length == 0)
{
PreviewHtml( encoding.GetBytes( "" ) );
return;
}
UnloadPreview();
//get type by clsid
Type previewerType = Type.GetTypeFromCLSID( guid );
//create instance
_officePreviewInstance = Activator.CreateInstance( previewerType );
var ows = (IObjectWithSite) _officePreviewInstance;
var ph = (IPreviewHandler) _officePreviewInstance;
var iwf = _officePreviewInstance as IInitializeWithFile;
var iws = _officePreviewInstance as IInitializeWithStream;
//now we need to initialize the object
if (iws != null)
{
var ms = new MemoryStream( _content );
var stream = new StreamWrapper( ms ); //File.Open(fileName, FileMode.Open));
iws.Initialize( stream, 0 );
}
else if (iwf != null)
{
iwf.Initialize( fileName, 0 );
}
else
{
throw new Exception( string.Format(
"Failed to locate an initialization interface for document type {0}", previewerType.FullName ) );
}
//set the current form (implements IPreviewHandlerFrame)
ows.SetSite( this );
previewPanel.Visible = true;
//set size
var rect = new RECT();
rect.left = 0;
rect.top = 0;
rect.bottom = previewPanel.Height;
rect.right = previewPanel.Width;
ph.SetWindow( previewPanel.Handle, ref rect );
ph.SetRect( ref rect );
//perform the preview
ph.DoPreview();
ph.SetFocus();
OnPreviewDocumentLoaded();
}