File transfer (File.Move() ) unexpected behavior

55 Views Asked by At

Im trying to move a file from one location to another.

        private void SendFileToDestination()
        {
            string file = "HATKANOT_BETIHOT_231230.txt";

            string sourceFilePath = Path.Combine(@"FTPUSERS\hoz_tbr\from\", file);

            string destinationFilePath = Path.Combine(@"C:\ARCHIVE\dgamim\CompanyC\", file);

            File.Copy(sourceFilePath, destinationFilePath);
        }

Ive hardcoded the paths since I was trying to overcome the issue Im going to detail below, but, the issue kept occuring.

So, the issue is that I get this error:

System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'E:\GalWorkspace\workspace\SlikaNetCore\Dgamim\bin\Debug\net8.0\FTPUSERS\hoz_tbr\from\HATKANOT_BETIHOT_231230.txt'.'

Im not sure why its looking under the entire E:\GalWorkspace\workspace\SlikaNetCore\Dgamim\bin\Debug\net8.0
as I never mentioned it in my code. What am I missing?

I was obviously expecting it to be transfered from one hardcoded location to another.

1

There are 1 best solutions below

0
Mureinik On

@"FTPUSERS\hoz_tbr\from\" is a relative path, so it's evaluated relatively to the current working directory. Seems like you want to have an absolute path, in which case it should strat with the drive name, e.g., @"C:\FTPUSERS\hoz_tbr\from\".