.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Rename File or folder in C#.net

Posted By:Narayanan       Posted Date: September 25, 2011    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

I think, No rename method in for renaming file or Folder.and then how to do this ?I explain this article. use "Move Method" do this work.Here I give a Code for rename file and Folder in c#.Net

1) Rename a File in C#.net

string path = @"C:\Documents and Settings\Narayanan\My Documents\Others\Txt\test\";
        string Orgifile = path + "\\Test.txt";
        string Renamefile = path + "\\Test1.txt";
        File.Move(Orgifile, Renamefile);

2) Rename a Folder in C#.net

string path = @"C:\Documents and Settings\Narayanan\My Documents\Others\Txt";
string OriFolder = path + "\\test";
string RenameFolder = path + "\\Test1.txt";
Directory.Move(OrgiFolder, RenameFolder);


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend