سؤال

When I read a file from a network share it updates the creation time to the last write time. This causes me problems with System.Configuration.Configuration because it thinks the file has changed and therefore throws an exception (The configuration file has been changed by another program.). The workaround would be to set the creation time to the last write time manually beforehand. But I'd like to know whether this is a known problem.

Here is some test code:

    string filePath = @"X:\SomeFile.txt";
    FileInfo fileInfo = new FileInfo(filePath);
    DateTime creationTimeBeforeRead = fileInfo.CreationTimeUtc;
    FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    byte[] result = new byte[fileStream.Length];
    fileStream.Read(result, 0, (int)fileStream.Length);
    fileStream.Close();
    fileInfo.Refresh();
    DateTime creationTimeAfterRead = fileInfo.CreationTimeUtc;

I have no idea if the problem lies within .net, the Windows API or on the server side. Does anyone have any insight?

هل كانت مفيدة؟

المحلول

I know this is an old question but I came across it while organizing some image files at my home Linux server (very old NAS box). The file creation time was coming out to be the file copy time and I found out that the problem was due to EXT3 Linux file format not supporting it over any type of sharing (NFS and SAMBA). Moving the files to an EXT4 and XFS file system format solved the problems for me.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top