File.WriteAllText 抛出 UnauthorizedAccessException

发布于 2024-08-07 18:34:43 字数 150 浏览 2 评论 0原文

对远程路径执行 File.WriteAllText 会引发 UnauthorizedAccessException。当我在记事本中打开文件时,我可以毫无问题地编辑它。尝试修改文件的进程正在以我自己的用户帐户运行,因此它应该能够访问它。

Doing File.WriteAllText to a remote path throws UnauthorizedAccessException. When I open the file in notepad I can edit it without a problem. The process that's trying to modify the file is running as my own user account, so it should be able to access it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北凤男飞 2024-08-14 18:34:43

如果文件设置了“隐藏”属性,也会引发 UnauthorizedAccessException。别问我为什么...

The UnauthorizedAccessException is also thrown if the file has the "hidden" attribute set. Don't ask me why...

抹茶夏天i‖ 2024-08-14 18:34:43

根据MSDNUnauthorizedAccessException也可以是造成的:

path 指定了一个只读文件。

-或者- 

当前平台不支持该操作。

-或者- 

路径指定一个目录。

这些情况之一是否可能是导致您出现问题的原因?

According to MSDN, UnauthorizedAccessException can also be caused by:

path specified a file that is read-only.

-or- 

This operation is not supported on the current platform.

-or- 

path specified a directory.

Is it possible one of these conditions is the cause of your problem?

送你一个梦 2024-08-14 18:34:43

我相信如果文件被另一个进程或线程锁定,您也会遇到此异常(尽管没有记录)。

确保没有其他任何东西以禁止写入的方式打开该文件。记事本不是一个很好的测试来查看文件是否被锁定,因为它会打开锁定的文件(即:只读文件很好)。

I believe you also get this exception (although its not documented) if the file is being locked by another process or thread.

Make sure nothing else has opened the file in a manner that prohibits writing. Notepad is not a good test for seeing if a file is locked, since it will open a locked file (ie: read-only files are fine).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文