0

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'.

4

2 回答 2

0

您可以将 xps-IThumbnailProvider 用于 zip 文件,无需自己编写!!!

将缩略图添加到您的 zip 文件中:

文件不能有 BOM !!!

如果将文件重命名为 .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

然后将您的文件扩展名添加到注册表(ClassesRoot 或 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}"

就这样...

于 2016-06-21T15:44:38.690 回答
0

与 OPC 格式无关。Windows 有自己的方式为每个文件扩展名绘制图标。要为特定文件扩展名绘制特定图标,您需要创建一个 dll,该 dll 实现 IThumbnailProvider 接口并注册它。更多信息在这里

于 2016-04-20T11:43:14.157 回答