There is no "rename" function in the C# File classes; what you need to do is to use the
File.Move()
method
string fileNameOld = fileName;
string fileNameNew =
string pathFileOld =
string pathFileNew =
try {
if ((File.Exists(pathFileOld) && (!FileExists(pathFileNew)) {
File.Move(pathFileOld, pathFileNew);
} else {
}
} catch(Exception ex) {
}
Reference:
File.Move Method (System.IO) | Microsoft Docs[
^]