1

I am trying to copy a file from a location on the C drive to a mapped network drive (Z) which is \address\content\

However I am getting the following error message:

System.UnauthorizedAccessException: Access to the path '\\192.168.100.227\content\2-Banner-20120402120304.png' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Admin.Controllers.OffersController.UploadNewFiles(OfferModel offer)

I have checked security setting for the directory and I can see that the following user does have full access on on the folder

  • IUSER
  • SYSTEM
  • NETWORK SERVICE
  • Rack
  • steven.wade
  • Administrators
  • Users

Any ideas why I can't copy their via ASP.NET?

Steven

RB.
  • 36,301
  • 12
  • 91
  • 131
swade1987
  • 1,663
  • 5
  • 21
  • 28

2 Answers2

0

Tag indicates a mapped drive and thats not going to work as these drives are not mapped for these users (its not a system wide setting).

Even if this isn't using a mapped drive but a share its really a bad idea to do this, What I've done before is to implement a FileWatcherService using the FileSystemWatcher class and copied using the api on that, the service runs as a known DOMAIN user and this has all the permissions. Just as easy to then drop the file in the monitored directory, your service can clean up that file after the copy is verified, seems a bit neater to me.

You can even write back a file to another directory and monitor that to check its been copied :)

krystan honour
  • 6,523
  • 3
  • 36
  • 63
  • Hi Krystan, do you happen to have a zip version of this application? – swade1987 Apr 02 '12 at 13:12
  • Nope i wrote it for a company and do not own the code, besides no offense but I kind of get paid to write that stuff. Its no biggie though there are tons of links on google like this: http://forums.asp.net/t/1438769.aspx/1 – krystan honour Apr 02 '12 at 14:00
0

You are copying files from one computer to the other, but NETWORK SERVICE is local account, which is different for both computers. So you need a domain account to run your worker process.

IvanH
  • 5,039
  • 14
  • 60
  • 81