There is no separate method for renaming the files and folders in c#. But we can achieve this by using Move method which is in File and Directory class.
Note: Please add System.IO namespace.
Renaming a File in C#
string path = Server.MapPath("~");
string Fromfile = path + "\\[Foldername] \\" +[Filename];
string Tofile = path + "\\[Foldername]\\" +[Filename];
File.Move(Fromfile, Tofile);
Renaming a Folder in C#
string path = Server.MapPath("~") ;
string Fromfol = "\\[Foldername] \\";
string Tofol = "\\[Foldername] \\";
Directory.Move(path + Fromfol , path + Tofol);
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

govind rajPosted May 26, 2017, 1:52 AM
If i upload the multiple file how to rename
govind rajPosted May 26, 2017, 1:51 AM
How to rename the multiple file name