You want to rename a file using C# language. But C# doesn’t provide you any functionality to do this. The only way you can use to do this is first copy the file with required name in the same directory and then delete the first file. This is a bit long procedure for this problem, as you can rename the file just by moving the file from one directory to another(in our case the destination directory is same to source directory) with changed name. You just enter the following line of code to rename your file.
This code will rename oldfile.txt to newfile.txt which is present in C:/ directory.
Note: In this method old file is moved from one directory to another. So, time taken to complete the process is dependant on file size.
Incoming search terms:
- c# rename file (17)