How to rename a File in C#?

By [)ia6l0 iii

There is no File.Rename method in C#. Use the System.IO.File.Move method instead.

System.IO.File.Move(@"C:\temp\file1.txt",@"C:\temp\file2.txt");

Related FAQs

Exception.ToString() contains a detailed description of the Exception with its stack trace. The Message property of the Exception object contains the smaller version of the description.
Explicity specify the NumberFormatInfo on the parse method of the int class and speed up the Parse Performance.
Use the Environment class to get important and user-specific properties like the User Profile folder.
Named and optional parameters is a new concept introduced in 4.0. The Named Parameters allow you to pass arguments by parameter name instead of parameter position in the signature. Optional Parameters allow parameters to be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted.
Extension method to get the start of a day
Use the DateTime object's 'Date' property to return the beginning of the day
How to rename a File in C#?  (1345 Views)