How To Ideas | How To Articles | How To Tutorials


0

How To Rename A File Using C#


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.

File.Move(@"C:\oldfile.txt", @"C:\newfile.txt");

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)
Filed in: C# Tags: , , , , , , , , , ,

Leave a Reply

Submit Comment



© 2013 How To Ideas. All rights reserved.
Proudly designed by Theme Junkie.