0

I try to copy a file to a mapped network drive, but I always get the message "Could not find a part of the path ...". I tried different mapped network drives, so I could exclude credential problems (it neither works with a drive connexcted with different credentials nor with my normal user)

  try
  {
     fi.CopyTo(SystemReg.TargetPath + fi.Name);
  }
  catch (Exception e)
  {
        SystemReg.Log.AppendLine("Copy failed! " + Environment.NewLine + e.Message);
  }

SystemReg.TargetPath is read from an XML file. If I use a local path like D:\temp\ it works perfectly, but e.g. X:\temp\ with X as a mapped drive it fails.

I also tried to run my program in a batch file with "net use..." before calling my program, it also fails.

Marco
  • 22,856
  • 9
  • 75
  • 124
Azrael
  • 385
  • 2
  • 5
  • 13
  • Drive names are scoped to your machine. The drive may have a total different name on any other machine. Use machine names. `\\MACHINE\folder$` – Marco Sep 28 '15 at 08:17
  • I still find that odd. *Are* you trying to access a drive you mapped on one computer from another computer where it isn't mapped? That would of course not work. But I assume you are on just one computer, the drive is mapped, you have permissions. You can copy manually (using the explorer). Reading the `FileInfo.CopyTo()` docs (https://msdn.microsoft.com/en-us/library/f0e105zt%28v=vs.110%29.aspx), I read that an `UnauthorizedAccessException` is thrown if "the file is being moved to a different drive." Ist that really so? Why? Why would it work if you substitute a machine name instead? – Peter - Reinstate Monica Sep 28 '15 at 09:30

1 Answers1

1

You shoud use computer address instead of drive name.

For example, if your computer's address is 192.168.0.200 which keeps shared folder temp\ then your full path is \\192.168.0.200\temp\

maxteneff
  • 1,523
  • 12
  • 28