以下代码使用 .Net Framework 2.0 从本地硬盘以管理员身份运行,有时会在第二行引发 UnauthorizedAccessException
:
IO.File.SetAttributes(File, IO.FileAttributes.Normal)
IO.File.SetAttributes(File, IO.FileAttributes.Archive)
这种情况发生在网络驱动器上。尽管读取和写入工作正常,但有缺陷的文件具有奇怪的权限(请参阅帖子末尾)。
更糟糕的是,即使从资源管理器中,尝试更改权限也会失败,首先请求管理员权限,然后仍然失败:
有什么想法吗?我完全不知所措。
这是文件权限的屏幕截图:
这个有效:
这个无效:
The following code, running as administrator from local hard drive, using the .Net Framework 2.0, sometimes raises an UnauthorizedAccessException
on the second line:
IO.File.SetAttributes(File, IO.FileAttributes.Normal)
IO.File.SetAttributes(File, IO.FileAttributes.Archive)
This happens on a network drive. The faulty files have weird permissions (see end of post), although reading and writing work perfectly.
Worse, even from Explorer, trying to change permissions fail, first asking for admin rights, then failing anyway:
Any ideas? I'm at a complete loss.
Here's a screenshot of file permissions:
This one works:
This one does not:
发布评论
评论(1)
我根本不太懂法语(这是正确的语言吗?),但看起来第一个有效,因为你是服务器端的用户(Linux 用户)。通过网络驱动器工作时,您必须拥有服务器上的权限才能更改文件属性。否则,就必须在服务器端进行更改。
编辑:某些服务器还可以在保存到网络驱动器时更改文件权限,具体取决于服务器设置和文件类型。这些更改可能会被锁定,只有具有服务器凭据的人才能修改它们,然后代码会因该异常而失败。
Edit2:也有可能它也可以通过索引绑定在服务器端,几分钟后,您将重新获得访问权限。
I don't know French much at all( that is the language correct?) but it looks like the first one works because you are a user on the server side (Linux user). When working over network drives, you have to have permissions on the server to change file attributes. Otherwise, it will have to be changed on the server end.
Edit: Some servers also can change file permissions when saved to a network drive depending on the server settings and type of file. These changes may be locked down to only someone with server credentials can modify them and the code then fails with that exception.
Edit2: It's also possible that it also could be tied down on the server end by indexing and after a few minutes, you will get acccess back.