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.
views:
321answers:
2
+3
A:
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?
Jay Riggs
2009-10-06 15:37:54
Ouch, correct, it was a directory. Silly me.
ripper234
2009-10-07 06:19:43
A:
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).
Reed Copsey
2009-10-06 15:45:33
In notepad I can actually edit the file. Why can't I modify it from .Net?
ripper234
2009-10-07 06:12:17
Try SAVING the file. Notepad will always open a file unless it's locked for exclusive read (which is very rare) - but you won't be able to save it over the top, usually - you'll have to use SaveAs...
Reed Copsey
2009-10-07 15:54:09