Question

I am trying to set the creation time of a directory with C#.

This works very easy with files in this way:

FileInfo fi = new FileInfo(strFile);
fi.CreationTime = DateTime.Now;

So I tried it with a path to a directory and got an object (so FileInfo worked on a directory) and it threw an UnauthorizedAccessException when setting the time like in the code above.

I am working on Windows 7 64bit and have administrator-rights on.

Question: So, how can I set the creation time of a directory?

Was it helpful?

Solution

I got it with this, haven't seen it yet....

Directory.SetCreationTime(strFile, DateTime.Now);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top