Alex Rivera | Logout

How can I rename a file in ASP.NET?

Asked 2010-01-29T08:44:52.690
9

In my project I want to rename the file before it is updating. For example a file in my system like Mycontact.xls. I want to rename it as sasi.xls (it is an excel file). How can I write the code in ASP.NET?

Actually I am using a fileupload control to get the file in and rename the file and upload the renamed file in a folder which is in Solution Explorer.

Edit
Report

1 Answer

10

You can do it with the File.Move method eg:

string oldFileName = "MyOldFile.txt";
string newFileName = "MyNewFile.txt";
File.Move(oldFileName, newFileName);
answered 2010-01-29T08:50:41.133

Your Answer