The Copy method copies an existing file to a new file on the specified location. The Copy method takes two parameters. First the file name to be copied to with full and the second parameter that is optional that is used to overwrite an existing file. If the second parameter is true, the Copy method will overwrite if file already exists.
The following code snippet copies a file to the destination file.
string fileName = @"C:fileName.txt"; FileInfo filetoCopy = new FileInfo(fileName); string destinationFile = @"C:destinationFile.txt"; try { filetoCopy.CopyTo(destinationFile, true); } catch (IOException iox) { Console.WriteLine(iox.Message); }