C# Program to make a copy of an existing file


Use File.Copy method to make copy of an existing file.

Add the path of the file you want to copy.

String myPath = @"D:\one.txt";

Now copy the above file to the following file −

String myPath = @"D:\one.txt";

Use the File.Copy method with both the source and destination file.

File.Copy(myPath,newpath);

Example

using System;
using System.IO;
public class Program {
   public static void Main() {
      String myPath = @"D:\one.txt";
      // the file will get copied here
      String newpath = @"D:\two.txt";
      // copying file
      File.Copy(myPath,newpath);
   }
}

Updated on: 23-Jun-2020

744 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements