Moving a file from one location to another

In this operation, we basically cut the file from one location and paste it into another. The following code snippet shows how this can be done:

string sourceFileLocation = "C:\UCN Code Base\Programming-in-C-Exam-70-483-MCSD-Guide\Book70483Samples\Chapter 20\IO Operations.txt";
string targetFileLocation = "C:\UCN Code Base\Programming-in-C-Exam-70-483-MCSD-Guide\Book70483Samples\Chapter 21\New File.txt";
if (File.Exists(sourceFileLocation))
{
File.Move(sourceFileLocation, targetFileLocation);
}
else
{
Console.WriteLine("File does not exists in the mentioned path");
}

In the preceding code snippet, we are first checking whether the file exists in a particular location. If the file is present in the location, we are copying it into another location.

Once the code is executed, we will notice that the file is cut from the source location and is pasted in to the target location. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.68