如何在c#中更改文件名?

时间:2014-11-07 07:27:17

标签: c#

我在文件对话框中返回文件名时遇到问题。 我只需要更改文件名而不是路径 我想要这样的东西......

string name_to_change="abc";
string filenameAtClient = this.saveFileDialog.FileName;
filenameAtClient=name_to_change;

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

string name_to_change = "abc";
string filenameAtClient = this.saveFileDialog.FileName;
filenameAtClient = filenameAtClient.Replace(Path.GetFileName(filenameAtClient), name_to_change);

没有文件扩展名的OR:

string name_to_change = "abc";
string filenameAtClient = this.saveFileDialog.FileName;
filenameAtClient = filenameAtClient.Replace(Path.GetFileNameWithoutExtension(filenameAtClient), name_to_change);