0

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.

2
  • 6
    You're using a relative path, FTPUSERS\hoz_tbr\from\file, this will be relative to something, which, depending on how you start the process, can be the folder where the executable is located. If you are talking about a specific folder named FTPUSERS, you should use an absolute path to it, such as E:\FTPUSERS\... or similar. Commented Jan 15, 2024 at 9:14
  • 3
    It is the current working directory. Commented Jan 15, 2024 at 9:16

1 Answer 1

0

@"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\".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.