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

4

6

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?

Pudendum answered 13/2, 2012 at 5:22 Comment(0)
D
4

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

Degust answered 13/2, 2012 at 5:28 Comment(1)
How can I put user name and password to server2 when I copy file to server2?Clouded
E
2

Something like this

File.Copy(
    "C:\path\yourfile.txt", 
    "\\remote_hostname\path\destinationfile.txt");
Elderly answered 13/2, 2012 at 5:26 Comment(0)
D
1

Try this

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

Divertimento answered 13/2, 2012 at 5:29 Comment(0)
A
0
   ' 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)
Actuate answered 16/7, 2019 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.