How to move a file from one location to another location?
Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.
How to move a file from one location to another location?
Rating:
The steps to move a file from one location to another location are as follows:
- Implement the System.IO namespace as follows.
using System.IO;
- Enter the source path of the file that is to be moved and the destination path where the file is to be moved.
string source=@" d: emp est.txt ";
string destination=@" d:\Myapp emp1 est.txt ";
- Check whether the source file exists. If it does not exist, create it.
If(!File.Exists(source)
{
//This block is executed only when source file does not exist
FileStream fs=File.Create(source);
}
- Ensure that the target does not exist.
If(File.Exists(destination)
File.Delete(destination);
- Move the file.
File.Move(source, destination);
- Close the FileStream class, if used.
fs.Close();
Rating:
Was this information helpful?
Other articles
- What are Platform Invocation Services?
- What is IIS?
- How to raise an event?
- How to write text to a file?
- How to set base address in the Integrated Development Environment (IDE)?
