C# Program to make a copy of an existing file

CsharpProgrammingServer Side Programming

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);
   }
}
raja
Published on 11-Sep-2018 12:56:49
Advertisements