Xel
Xel

Reputation: 571

How to use File.Copy C# method to copy files over LAN?

I want to make a WinForms Application that can copy files over a LAN. Using File.Copy seems a straightforward way to do this. The example given here shows how to copy a file to a different directory on the same computer. How can I use File.Copy to copy files from one computer to another which belongs to the same LAN?

Upvotes: 6

Views: 5932

Answers (4)

Farrukh Azad
Farrukh Azad

Reputation: 19

   ' 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)

Upvotes: 0

Anantha Sharma
Anantha Sharma

Reputation: 10108

you can try

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

also make sure to use UNC path.. here are some references. - Link - Link - Link

Upvotes: 4

Developer
Developer

Reputation: 8646

Try this

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

Upvotes: 1

Dmitry Savy
Dmitry Savy

Reputation: 1067

Something like this

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

Upvotes: 2

Related Questions