Copy File Using Copy method
using System.IO;
using System;
//Program to copy an existing file to new file.
class CopyFile
{
static void Main()
{
string MyFile = "D://MyFile.txt"; // Source File
string NewFile = "D://NewFile.txt"; // Destination File
if (File.Exists(MyFile)) // Checks for the existence of source file
{
// If destination file already exists, delete it.
if (File.Exists(NewFile))
File.Delete(NewFile);
File.Copy(MyFile, NewFile); // Copies file from MyFile to NewFile
Console.WriteLine("Copied Successfully");
}
Console.ReadLine();
}
}
Output:
Copied Successfully