The Move method moves an existing file to a new location with the same or a different file name. The Move method takes the full path of the move file. The Move method deletes the original file.
The following code snippet moves the source file to the destination file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Program { static void Main(string[] args) { string fileName = @"E:\file.txt"; FileInfo filetomove = new FileInfo(fileName); string destinationFile = @"E:\myfolder\"+ filetomove.Name; try { filetomove.MoveTo(destinationFile); } catch (IOException ex) { Console.WriteLine(ex.Message); } //Console.ReadLine(); } } |