简体   繁体   中英

Copy file fo mapped network drive using FileInfo.CopyTo

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 eg 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.

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\\

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM