My application checks on startup if there is a newer version of a file on a shared network drive. If the one on the network share is newer it copies it to the local application directory and overwrites the old one. My current code to do this goes something like this:
FileInfo sourceFile = new FileInfo(source + "\\" + fileName);
if(sourceFile.Exists) {
FileInfo destFile = new FileInfo(destination + "\\" + fileName);
if (destFile.Exists && destFile.LastWriteTime >= sourceFile.LastWriteTime)
{
//Using log4net
log.Info("Current " + fileName + " is newer than the one on the server.");
return false;
}
}
Checking the logs, it seems that sometimes the LastWriteTime
of the source file is not being detected as newer (event when it is). Am I possibly getting write times and modified times confused? Does anybody have an idea of how to achieve this?
EDIT (and copy of my comment below): The files I am copying are mostly DLLs which I have control over. They are assemblies for the application "Growl for Windows"; they define custom displays. The intent of my application is to check the network share to see if there is a newer version available and to copy that locally if required. That way, we can help to ensure that all our clients are using the most up-to-date display.
EDIT 2:
OK, I fooled around with loading the assemblies and I ran into another problem. It seems you cannot load the same file twice, even if they are from different locations, when they're loaded via Assembly.ReflectionOnlyLoadFrom