Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know last modified user of any file in c#? [duplicate]

I am trying to get last modified by user name but I am not able to get the user name. I searched lot on Google but I am confuse now. Because In some thread I found that last modified user is not able to get. And Other link gives some code. I used that code but last modified user is not getting retrieved.

Is there any one who get the last modified user name using c# code?
Is it possible?


1 Answers

This should give you the last modified file and the user who changed it:

var dir = new DirectoryInfo(path);
var lastModified = dir.GetFiles()
    .OrderByDescending(fi => fi.LastWriteTime)
    .First();
string modifiedBy = lastModified.GetAccessControl()
    .GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();

"Powered by": Finding the user who modified the shared drive folder files

Edit: actually this gives you only the owner of the file that was last modified.

It seems that windows simply doesn't keep track of this. You could use a FilesystemWatcher to do it yourself.

like image 100
Tim Schmelter Avatar answered Nov 17 '25 20:11

Tim Schmelter