File.WriteAllText throws UnauthorizedAccessException

Execution File.WriteAllTextfor the remote path calls UnauthorizedAccessException. When I open the file in notepad, I can edit it without any problems. The process that is trying to modify the file works like my own user account, so it must have access to it.

+3
source share
3 answers

According to MSDN , UnauthorizedAccessExceptionit can also be called:

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 that one of these conditions is causing your problem?

+7
source

UnauthorizedAccessExceptionalso called if the hidden attribute is set in the file. Do not ask me why ...

+10

, ( ), .

Make sure nothing else opens the file in a way that prohibits writing. Notepad is not a good test for a file being locked, as it will open a locked file (i.e.: read-only files are okay).

+1
source

Source: https://habr.com/ru/post/1719406/


All Articles