Move File Using Move method
using System.IO;
using System;
//Moving file from one location to other using Move method of class File
class MoveFile
{
static void Main()
{
string fileloc1 = "D://MyFile.txt";
string fileloc2 = "G://MyFile.txt";
if (File.Exists(fileloc1)) //Checks for the existence of source file
{
// If destination file already exists, delete it.
if (File.Exists(fileloc2))
File.Delete(fileloc2);
File.Move(fileloc1, fileloc2); // Moves fileloc1 to fileloc2
Console.WriteLine("File moved successfully");
}
Console.ReadLine();
}
}
Output:
File moved successfully