[C#] How to Move a File in C#

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.

string fileName = @"C:\fileName.txt";
FileInfo filetomove = new FileInfo(fileName);
string destinationFile = @"C:\destinationFile.txt";
try
{
	filetomove.MoveTo(destinationFile);
}
catch (IOException ex)
{
	Console.WriteLine(ex.Message);
}
Xem thêm  [C#] How to Create a File

You may also like...

1 Response

  1. 03/03/2019

    […] [C#] How to Move a File in C# […]

Leave a Reply

Your email address will not be published. Required fields are marked *