简体   繁体   中英

File.Copy access to path denied

I am trying to copy files at specific directory from my pc to remote pc (server) as shown below but I am getting an error message access to path denied

I tried to copy files to my local pc not the remote one and filed for the same reason

I also tried to run the exe as administrator form Debug foleder but I got same error message

another question for now the remote pc has no password or username so can I use same way but with password authentication ?

private void PatchUpdates()
{
    try
    {
        string[] array = Directory.GetFiles(Sfilespath, "*.txt");

        foreach (string name in array)
        {
            MessageBox.Show(Path.GetFileNameWithoutExtension(name));
            MessageBox.Show(@"D:\" + Path.GetFileNameWithoutExtension(name));
            File.Copy(Sfilespath, @"D:\" + Path.GetFileNameWithoutExtension(name), true);
        //File.Copy(SBankfilespath, "\\\\192.168.1.28\\Files");


        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

The problem might be the source of the copy command, not the destination. Try to pass the found file names instead of the path where you are looking for files: File.Copy(name, @"D:\\" + Path.GetFileNameWithoutExtension(name), true);

You can probably just run net use \\\\\\\\192.168.1.28\\\\Files /user:username password using Process.Start before copy the files. Or check Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials for a proper solution.

I got "access denied" while copying from one network folder to the other. I solved it by defining a specific identity for relevant the application pool, a user which has access to the path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM