Keep timestamp from updating on network disconnect


New member
Aug 20, 2013
Programming Experience
I have created my own custom file copier class. I'm using it for multiple file transfers across a WAN that is sometime unreliable to many machines.
When I initiate the file transfer, it sets the timestamp on the destination file to 1/1/1981, then when the file transfer finishes, it updates the timestamp to match the source file.
This is similar behavior to RoboCopy.
The reason I do this is the program can resume a file transfer if it's interrupted, but if the destination file is newer than the source, it will skip the file. This runs into problems when destination machine temporarily drops off the network. When that happens, the filestamp on the incomplete file suddenly updates to the current time. This is not desired. Any ideas how I can fix this?

This is a snippet of the relevant code that starts and does the copy:

m_Dest = new FileStream(DestFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

FileInfo FI = new FileInfo(DestFilePath);
FI.LastWriteTimeUtc = new DateTime(1, 1, 1981)
FI = null;

m_Dest = new FileStream(DestFilePath, FileMode.Truncate, FileAccess.Write, FileShare.None, m_Buffer.Length);
m_Buffer = new byte[1024 * 4]

while (CurrentBlockSize > 0){
CurrentBlockSize = m_Source.Read(m_Buffer, 0, m_Buffer.Length);
m_Dest.Write(m_Buffer, 0, m_CurrentBlockSize);
The source system is Windows 2003, destination is Windows XP. It seems when I test this on windows 7 to another windows 7 machine, the timestamp doesn't get updated.
Top Bottom