C# Copy a file to another location with a different name
System.IO.File.Copy(oldPathAndName, newPathAndName);
You may also try the Copy method:
File.Copy(@"c:\work\foo.txt", @"c:\data\bar.txt")
Use the File.Copy method instead
eg.
File.Copy(@"C:\oldFile.txt", @"C:\newFile.txt");
You can call it whatever you want in the newFile, and it will rename it accordingly.
If you want to use only FileInfo class try this
string oldPath = @"C:\MyFolder\Myfile.xyz";
string newpath = @"C:\NewFolder\";
string newFileName = "new file name";
FileInfo f1 = new FileInfo(oldPath);
if(f1.Exists)
{
if(!Directory.Exists(newpath))
{
Directory.CreateDirectory(newpath);
}
f1.CopyTo(string.Format("{0}{1}{2}", newpath, newFileName, f1.Extension));
}