How to get file owner from network drive in C #?

How to get file owner from network drive file in C #?

I am using this code:

string user = System.IO.File.GetAccessControl("filepath").GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();

I get the name of the file owner if the domain of the file owner matches my machine, but if the domain is different from my computer, then I get the error message " Some or all of the identifier links cannot be translated ."

Can this be done?

+3
source share
2 answers
string user = File.GetAccessControl("filepath").GetOwner(typeof(SecurityIdentifier)).Translate(typeof(NTAccount)).ToString();
0
source

You can try the below snippet,

string Owner = File.GetAccessControl("path").GetOwner(typeof(SecurityIdentifier)).Translate(typeof(NTAccount)).ToString();

You need to have access to it

0
source

All Articles