You Can use this Code to rename a file , although you Can Alternatively use Code in Second Solution Given at Next Renaming Way:-
FileInfo fi = new FileInfo("NameToBeRename.jpg");
{
if (!File.Exists("NewName.jpg"))
{
fi.MoveTo("NewName.jpg");
}
}
You also use following Code
if (!File.Exists("NewName.jpg" && File.Exists("NameToBeRename.jpg")))
{
File.Move("NameToBeRename.jpg,"
NewName.jpg"
");
}