简体   繁体   English

如何从C#中的网络驱动器获取文件所有者?

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

How do I get file owner from network drive file in c# ? 如何 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 您需要访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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