简体   繁体   中英

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

How do I get file owner from network drive file in c# ?

I use this code:

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

I get the file owner name if the domain of file owner is the same as my machine, but if domain is different than my machine then I get error that " Some or all identity references could not be translated ."

Is it possible to do this?

string user = File.GetAccessControl("filepath").GetOwner(typeof(SecurityIdentifier)).Translate(typeof(NTAccount)).ToString();

You can try below snippet,

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

You need to have access on it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM