Error creating folder on remote server

Hi I have written code for writing a file to a remote server in .net. When I save the output path as a local disk, the code works fine and creates folders and text files. But when I point to the remote server, I get below the error:

System.UnauthorizedAccessException: Access to the path '\\ServerName\FolderTest\FolderTest1\AB.txt' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at ... 

If you need more information, let me know.

+4
source share
3 answers

Now the code worked correctly. The problem was access. The credentials with my code written to the folder were not added to the folder security tab. After adding to it. It worked. Thanks @James Deville, @VMAtm and @Razvan Panda :)

-1
source

In what environment do you execute your code? Winforms, web forms or winning services?
For all these cases, there are different problems to solve this problem:

  • WinForms - then your code runs according to your default credentials, so your account must have permissions for the creatinf folder on the remote server.
  • WebForms - then your code runs under the local IIS user by default or under your account if you are using impersonation , so these accounts must have permissions for the creatinf folder on the remote server.
  • Win-services - then your code is executed either under the local service, or on the local machine, or on the network, or by any user for this service ( see here for more information ), so the accounts must have permissions for the creatinf folder on remote server.
+1
source

You probably need to set permissions for the correct user in the folder where you want to save the file. This post may have an answer for you:

Link - System.UnauthorizedAccessException

0
source

All Articles