0

When I try to copy a file to a new destination, I get the error;

An exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll but was not handled in user code

Additional information: Could not find a part of the path '~/Content/fileHistory/Resume.pdf'.

However the file is there.

Here is my code, the fileName is found correctly;

            Random randNums = new Random();

            string fileName = documentUps.Attachment ;
            string newFileName = fileName + randNums;
            string sourcePath = "~/Content/fileHistory/";
            string targetPath = "~/Content/reviseFiles/";

            // Use Path class to manipulate file and directory paths.
            string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
            string destFile = System.IO.Path.Combine(targetPath, newFileName);

            System.IO.File.Copy(sourceFile, destFile, true);

https://gyazo.com/2d402824178738c6fb0f873904db6cdf

1 Answers1

0

can u please change this code to this :

        Random randNums = new Random();

        string fileName = documentUps.Attachment;
        string newFileName = fileName + randNums;
        string sourcePath = "~/Content/fileHistory/";
        string targetPath = "~/Content/reviseFiles/";

        // Use Path class to manipulate file and directory paths.
        string sourceFile = Server.MapPath(System.IO.Path.Combine(sourcePath, fileName));
        string destFile = Server.MapPath(System.IO.Path.Combine(targetPath, newFileName));

        System.IO.File.Copy(sourceFile, destFile, true);