如何在Windows资源管理器中刷新文件的缩略图? [英] How do I refresh a file's thumbnail in Windows Explorer?

查看:1806
本文介绍了如何在Windows资源管理器中刷新文件的缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  if(Directory.Exists(path))
{
DirectoryInfo di = new DirectoryInfo(path);
FileInfo [] potentiallyStubbedFiles = di.GetFiles();
foreach(fileInfo fi in potentiallyStubbedFiles)
{
//忽略Thumbs.db文件
if(!fi.Name.Equals(Thumbs.db))
{
Console.WriteLine(Reading+ fi.Name);
尝试
{
FileStream fs = File.Open(fi.FullName,FileMode.Open,FileAccess.Read,FileShare.None);

尝试
{
//读取文件的第一个字节,迫使它不被打开
byte [] firstByte = new byte [1];
fs.Read(firstByte,0,1);

catch(Exception ex)
{
Console.WriteLine(尝试读取时发生错误+ fi.Name +:);
}

fs.Close();

catch(Exception ex)
{
Console.WriteLine(试图打开的错误+ fi.Name +:);



Console.WriteLine(Finished reading files。);
}
else
{
Console.WriteLine(\+ path +\不是一个有效的目录。
}

效果很好,但我想解决一个小问题。在Windows 7中,当关闭FileStream时,Windows资源管理器将刷新该文件并显示正确的缩略图,以便您可以看到每个文件的缩略图,因为它们是未打开的。但是,在Windows XP中,只有在程序退出之后,Explorer才会刷新文件,强制用户等待全部文件在未能被浏览之前就被取消了。



有没有办法强制Windows XP在读取文件后立即重新创建文件的缩略图?程序关闭后刷新文件的信号是什么?或者我完全用错误的方式来解决这个问题?

解决方案

使用SHCNE_UPDATEITEM尝试SHChangeNotify。

Our Windows file server has an archive service installed that "stubs" files that have not been accessed for a defined period of time. When a request for the stubbed file is sent to the server, the archive service replaces the stub with the original document and serves it to the user.

A major complaint about the archive service was that thumbnails for photos were no longer available. I decided to create a program in C# that would allow the user to select a folder and unstub all the files in it. It does this by reading the first byte of each file in the folder:

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.");
}

It works well, but I have one small problem that I would like to resolve.

In Windows 7, when the FileStream is closed, Windows Explorer refreshes the file and shows the correct thumbnail, so you can see the thumbnail of each file as they are unstubbed. In Windows XP, however, Explorer does not refresh the files until the program exits, forcing the user to wait until all files have been unstubbed before being able to browse them.

Is there any way to force Windows XP to recreate the thumbnail for the file immediately after reading it? What signal is being given to refresh the files after the program closes? Or am I going about this the wrong way completely?

解决方案

Try SHChangeNotify with SHCNE_UPDATEITEM.

这篇关于如何在Windows资源管理器中刷新文件的缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆