Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

File.Copy - System.IO.FileNotFoundException occured: Could not find file

$
0
0

Hello All,

I am having issues with copy File. Below is the method.

When trying to copy the file from the source path to the destination path, it throws the error Could not find file ''. But the file exists in the path.

Please let me know as what is the issue in the below code.

private void CopyFile(string filename, string sourcePath, string destPath)
        {
            var targetPathFile = Path.Combine(destPath, filename);
            var sourcePathFile = Path.Combine(sourcePath, filename);
          
            if (!File.Exists(targetPathFile))
            {
                try
                {
                    File.Copy(sourcePathFile, targetPathFile, true);
                  
                }
                catch (Exception ex)
                {
                    throw ex;

                }
            }
        }


TIG


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>