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?