0

I have a C# code that moves a local file from folder to another following the code below:

 File.Move("C:\folder1\file.txt","C:\folder1\folder2\");

this code moves the file.txt to folder2 my problem is the file.txt exists on a shared directory so i need to access it and move it to second folder like this

 File.Move("\\shared directory\\folder1\\file.txt","\\shared directory\\folder2\\");

the code above didnt works any solution?

Malo
  • 1,232
  • 2
  • 17
  • 28
  • Does this help? https://stackoverflow.com/questions/1432213/copy-file-on-a-network-shared-drive – Slack Groverglow Mar 25 '18 at 22:05
  • Have you tried mapping the two shared folders to have drive letters in WIndows? so that `\\shared directory\\folder1` is `S:\\` and `\\shared directory\\folder2` is `T:\\` – Jake Mar 25 '18 at 22:05

2 Answers2

0

Try mapping the shared network drives to drive letters in Windows:

  1. Open Computer ([Win]+[E])
  2. Click the 'Computer' tab from the top ribbon
  3. Select the 'Map Network Drive'
  4. Select a drive letter and enter the first shared folder path(\\shared directory\folder1)
  5. Keep 'Reconnect at sign-in' checked if needed
  6. If you need to log in to access the shared folder with an account that is different to your windows login, check the Connect using different credentials box and enter the credentials when prompted.
  7. Repeat for \\shared directory\\folder2 selecting a different drive letter

From there you should be able to use the same code you mentioned was working:

File.Move("S:\file.txt","T:\");

Assuming S:\ is mapped to \\shared directory\folder1 and T:\ is mapped to \\shared directory\folder2\

Jake
  • 1,207
  • 2
  • 28
  • 46
0

Try File.Move(@"\\shared directory\folder1\file.txt", @"\\shared directory\folder2\");

R. StackUser
  • 2,005
  • 4
  • 17
  • 24
  • It's apparent that there's a file share issue. Are you sure that you are running the program as a user with access to the network share? If running as Admin, admin will need access rights to that share as well. – R. StackUser Mar 30 '18 at 15:57