【问题标题】:How to get file owner from network drive in C#?如何在 C# 中从网络驱动器获取文件所有者?
【发布时间】:2014-02-26 05:57:50
【问题描述】:

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

我使用这个代码:

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

如果文件所有者的域与我的机器相同,我会得到文件所有者名称,但如果域与我的机器不同,则会收到错误消息“无法翻译部分或全部身份引用强>。”

可以这样做吗?

【问题讨论】:

  • 您确定该文件不是只读的吗?
  • 是的,我可以完全访问文件
  • 这可能是因为当前用户不是域帐户...代码太短无法决定。
  • 是的,用户不是域帐户。但是如果我想检索用户名现在该怎么办
  • 如果你浏览到文件(右键文件->属性->安全->高级->所有者)你能正确看到所有者吗?

标签: c# .net file file-io


【解决方案1】:
string user = File.GetAccessControl("filepath").GetOwner(typeof(SecurityIdentifier)).Translate(typeof(NTAccount)).ToString();

【讨论】:

    【解决方案2】:

    你可以试试下面的sn-p,

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

    你需要访问它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多