Click here to Skip to main content
15,888,142 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi sir,
Tell me the steps to move the file from one system to another system over a network using asp.net c#. I developed using asp.net c# windows application, its working fine in local file transfer from localdisk C: drive to d: drive. But if i put ipaddress like "\\192.168.10.37\c$\prabu1", it will not move the file to that destination [192.168.10.37]. I attached the code for your reference. Give me a valuable feedback with the proper solution.

Code:
**************
C#
private void Form1_Load(object sender, EventArgs e)
{
    string source_directory = @"c:\datas";
    string destination_directory = @"\\192.168.10.37\d$\prabu1";
    
    DirectoryInfo sourceinfo = new DirectoryInfo(source_directory);
    DirectoryInfo destinationinfo = new DirectoryInfo(destination_directory);
    
    if (sourceinfo.Exists)
    {
        string s1 = sourceinfo.FullName;
        string d1 = destinationinfo.FullName;
        if (Directory.GetFiles(s1).Length > 0 && Directory.GetDirectories(s1).Length == 0)
        {
            if (destinationinfo.Exists)
            {
                string s = sourceinfo.FullName;
                
                foreach (var filenames in Directory.GetFiles(s1))
                {
                    //File.Move(str, Path.Combine(dir, Path.GetFileName(str)));
                    
                    string source_location = filenames;
                    
                    string prabu = Path.GetFileName(source_location);
                    
                    string myFile = source_location;
                    string fileToCopy = destination_directory+"\\"+prabu;
                    
                    if (File.Exists(fileToCopy))
                    {
                    File.Delete(fileToCopy);
                    }
                    File.Move(myFile, fileToCopy);
                }
            }
        }
    }
    else
    {
        //this.Close();
        notifyIcon1.BalloonTipText = "No such directory exists in that location";
        notifyIcon1.Visible = true;
        notifyIcon1.ShowBalloonTip(300, "Notify Icon", "No such directory exists in that location", ToolTipIcon.Error);
        //MessageBox.Show("No such directory exists in that location", "Folder not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
Posted
Updated 2-May-13 20:36pm
v2
Comments
Karthik Harve 3-May-13 2:37am    
[Edit] pre tags added.

1 solution

Please check my previous answer to another CPian. The same applies to your answer as well. You need to impersonate first to transfer files over network. Please check my answer here:how to store image or picture another server through LAN connection[^]

Good luck,
OI
 
Share this answer
 

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