How to use the File.Copy C # method to copy files over a local network?

I want to make a WinForms application that can copy files over a local network. Using File.Copy seems like an easy way to do this. The example below shows how to copy a file to another directory on the same computer. How can I use File.Copy to copy files from one computer to another that belongs to the same LAN?

+7
source share
4 answers

you may try

File.Copy(@"\\server\sourceFileFolder\file1", @"\\server2\destinationFileFolder\file1"); 

also be sure to use the UNC path. Here are some links. - Link - Link - Link

+5
source

Something like that

 File.Copy( "C:\path\yourfile.txt", "\\remote_hostname\path\destinationfile.txt"); 
+2
source

try it

File.Copy(@"\\server\folder$\test.txt", "test.txt");

+1
source
  ' code in Vb , convert it into C# Dim findDirectory = "D:\UOLQserver\Data\Sound\" Dim Y_N = System.IO.Directory.Exists(findDirectory) If Y_N = True Then Else Directory.CreateDirectory(findDirectory) End If Dim MyFilename1 = findDirectory & "\" & Today.Day & "-" & Today.Month & "-" & Today.Year & "-" & tineNow & "-" & Today.Minute & ".wav" FileCopy("\\SERVER\D$\UOLQserver\Data\Sound\test.wav", MyFilename1) 
0
source

Source: https://habr.com/ru/post/908300/


All Articles