Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
I want to know how to transfer files from one system to another using C#? I have tried using the Sharing the Destination Folder Path and transferring the files from source to destination.Is there any other ways using C#? The transfer of files will be initiated at the client only.The synchronization should happen between the client and server.

I have done as given below
C#
Impersonator obj = new Impersonator("admin", Environment.UserDomainName, "abc_123", LogonType.LOGON32_LOGON_NEW_CREDENTIALS, LogonProvider.LOGON32_PROVIDER_DEFAULT);

            if (!Directory.Exists(destinationPath))

                Directory.CreateDirectory(destinationPath + "\\" + DateTime.Now.ToString("ddMMyyyy"));

            string[] files = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories);

            // Get the Directory Information of the destination Path
            DirectoryInfo dirInformation = new DirectoryInfo(destinationPath);
            FileInfo[] destFileNames = dirInformation.GetFiles("*", SearchOption.AllDirectories);

            foreach (string eachFile in files)
            {
                string name = Path.GetFileName(eachFile);
                string dest = Path.Combine(destinationPath, name);

                if (File.Exists(dest))
                {
                    File.Delete(dest);
                    File.Copy(eachFile, dest, true);
                }
                else
                {
                    File.Copy(eachFile, dest, true);
                }
            }



I have done this using Impersonating the user and transferring the files to the shared path.
Posted
Updated 4-Apr-13 20:42pm
v2
Comments
Sergey Alexandrovich Kryukov 2-Apr-13 1:34am    
Do you think that counting some "ways" is programming? Totally pointless question, in that part.
This question it incorrect, and the question about pros and cons is also incorrect. It all depends on your goal, not something to be compared.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900