关于 c#:如何在 Windows 资源管理器中刷新文件的缩略图? | 珊瑚贝

How do I refresh a file’s thumbnail in Windows Explorer?


我们的 Windows 文件服务器安装了存档服务,用于”Stubbing”在定义的时间段内未访问的文件。当对Stubbing文件的请求发送到服务器时,存档服务会用原始文档替换Stubbing并将其提供给用户。

有关存档服务的主要抱怨是照片的缩略图不再可用。我决定在 C# 中创建一个程序,允许用户选择一个文件夹并取消Stubbing其中的所有文件。它通过读取文件夹中每个文件的第一个字节来做到这一点:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
if (Directory.Exists(path))
{
    DirectoryInfo di = new DirectoryInfo(path);
    FileInfo[] potentiallyStubbedFiles = di.GetFiles();
    foreach (FileInfo fi in potentiallyStubbedFiles)
    {
        //ignore Thumbs.db files
        if(!fi.Name.Equals(“Thumbs.db”))
        {
            Console.WriteLine(“Reading” + fi.Name);
            try
            {
                FileStream fs = File.Open(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.None);

                try
                {
                    //read the first byte of the file, forcing it to be unstubbed
                    byte[] firstByte = new byte[1];
                    fs.Read(firstByte, 0, 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(“An error occurred trying to read” + fi.Name +“:”);
                }

                fs.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(“An error occurred trying to open” + fi.Name +“:”);
            }
        }
    }
    Console.WriteLine(“Finished reading files.”);
}
else
{
    Console.WriteLine(“”” + path +”” is not a valid directory.”);
}

效果很好,但我有一个小问题想解决。

在 Windows 7 中,当 FileStream 关??闭时,Windows 资源管理器会刷新文件并显示正确的缩略图,因此您可以看到每个文件的缩略图,因为它们是未Stubbing的。但是,在 Windows XP 中,资源管理器在程序退出之前不会刷新文件,这迫使用户等到所有文件都被取消Stubbing后才能浏览它们。

有什么方法可以强制 Windows XP 在读取文件后立即重新创建文件的缩略图?程序关闭后刷新文件的信号是什么?还是我完全走错了路?

  • 这个问题让我很感兴趣。我添加了赏金。
  • 从那以后我就没有运气了。但是,我注意到如果我强制线程hibernate几秒钟,任何已处理的文件都将被刷新。
  • 好吧,如果你确实解决了它,请在一周内将你的答案作为这篇文章的答案,我会给你赏金:p。
  • 请参阅我对以下已接受答案的评论。非常感谢您在获得解决方案方面的帮助! :)
  • 既然你认为这是正确的,我已经授予了赏金。没问题,这是一个有趣的问题。


似乎没有与 Windows XP 相关的界面。 Vista及以上版本引入IThumbnailCache接口。

你不能删除 thumbs.db 并强制这样做吗?

thumbs 的格式没有记录,但是 http://vinetto.sourceforge.net/ 上有一个项目试图理解它,如果你想深入研究,可能会给一些指示。

  • 感谢您的回答,但更改 thumbs.db 不会让我实时刷新文件缩略图。


使用 SHCNE_UPDATEITEM 尝试 SHChangeNotify。

  • 我花了很多时间试图让 SHChangeNotify 工作但没有成功。如果我可以调试 dll 方法调用,那将是一个很大的帮助。有没有办法做到这一点?
  • 注意传递正确的 SHCNF_PATH 参数(例如,Unicode 的 SHCNF_PATHW)。如果可以的话,传递文件的pidl。
  • 谢谢。我最终让它工作了。这是在取消Stubbing文件后我可以调用 refreshThumbnail(fi.FullName) 的 ShellNotification 类:pastebin.com/7VnfiKX6 目前有点粗糙,但可以完成工作。我使用的其他来源是:viewontv.codeplex.com/SourceControl/changeset/view/52406#939??762 和 social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/??…
  • 您正在泄漏pidl。使用 ILFree 释放 SHParseDisplayName 中分配的 pidl。


来源:https://www.codenong.com/3555799/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9383.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?