Skip to content

File.SetLastWrite time fails on readonly files on Windows #62602

Closed
@danmoseley

Description

@danmoseley
            string path = Path.GetTempFileName();

            File.SetLastWriteTime(path, new DateTime(2000, 1, 1)); // succeeds
            File.SetAttributes(path, FileAttributes.ReadOnly); 
            File.SetLastWriteTime(path, new DateTime(2001, 1, 2)); // throws UnauthorizedAccessException

This is because SetLastWrite time tries to open a file handle with GENERIC_WRITE instead of only FILE_WRITE_ATTRIBUTES. This bug exists in .NET Framework as well and has been encountered by customers eg here and now reported in a DTS issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions