Show thumbnail of an OPC file in Windows Explorer

239 views Asked by At

I have an OPC-file. It works fine. Now I'm trying to add thumbnail, so when this file is shown in Windows Explorer or, for example, as attachment in browser, my thumbnail is displayed.

I tried to add

<Relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="/thumbnail.png" Id="RTN1" />

to .rels file. I tried to add jpeg instead of png. I tried 32x32 and 64x64 sizes.

[Content_Types].xml:

<Default Extension="png" ContentType="image/png" />

or <Default Extension="jpeg" ContentType="image/jpeg" />

Structure of my file:

  • _rels
    • .rels
  • thumbnail.png
  • other files
  • [Content_Types].xml

A markup example of working OPC-file with thumbnail and it's structure will me much appreciated.

EDIT 2:

I've managed to show thumbnail when extension of a file is 'xps'.

2

There are 2 answers

0
Andrii Muzychuk On BEST ANSWER

There is nothing to do with OPC format. Windows have it's own way to draw icon for each file extension. To have a specific icon drawn for a specific file extension you need to create a dll, which implements IThumbnailProvider interface and register it. More info here.

0
Thomas Hoerhan On

You can use the xps-IThumbnailProvider for zip-files, no need to write your own one !!!

Add the Thumbnail to your zip-file:

Files must not have a BOM !!!

Try until your file displays the thumbnail if you rename it to .xps

Public WriteOnly Property Thumbnail As Image
        Set(value As Image)
            If value IsNot Nothing Then
                Dim relsdir = Me.ZipArchivWriter.CreateEntry("_rels/", CompressionLevel.NoCompression)
                Using rels = Me.ZipArchivWriter.CreateEntry("_rels/.rels", CompressionLevel.Fastest).Open
                    Using w As New StreamWriter(rels, FXENCODING)
                        w.WriteLine(XMLSTART)
                        w.WriteLine("<Relationships xmlns=""http://schemas.openxmlformats.org/package/2006/relationships"">")
                        w.WriteLine("<Relationship Target=""thumbnail.png"" Id=""R1"" Type=""http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail"" />")
                        w.WriteLine("</Relationships>")
                    End Using
                End Using
                Using ct = Me.ZipArchivWriter.CreateEntry("[Content_Types].xml", CompressionLevel.Fastest).Open
                    Using w As New StreamWriter(ct, FXENCODING)
                        w.WriteLine(XMLSTART)
                        w.WriteLine("<Types xmlns=""http://schemas.openxmlformats.org/package/2006/content-types"">")
                        w.WriteLine("<Default Extension=""rels"" ContentType=""application/vnd.openxmlformats-package.relationships+xml"" />")
                        w.WriteLine("<Default Extension=""PNG"" ContentType=""image/png"" />")
                        w.WriteLine("</Types>")
                    End Using
                End Using
                Using tn = Me.ZipArchivWriter.CreateEntry(FXTHUMBNAIL, CompressionLevel.NoCompression).Open
                    value.Save(tn, ImageFormat.Png)
                End Using
            End If
        End Set
    End Property

And then add your file-extension to the registry (ClassesRoot or CurrentUser):

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\.frax\shellex\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]
@="{44121072-A222-48f2-A58A-6D9AD51EBBE9}"

[HKEY_CURRENT_USER\Software\Classes\.frax\shellex\{e357fccd-a995-4576-b01f-234630154e96}]
@="{44121072-A222-48f2-A58A-6D9AD51EBBE9}"

[HKEY_CURRENT_USER\Software\Classes\.frax\shellex\PropertyHandler]
@="{45670FA8-ED97-4F44-BC93-305082590BFB}"

That's all...