0

我使用 ASP.net 并在网站上有一个 .docx 文件:

Server.MapPath("~") + @"Files\tmp.docx". 

我想将此文件复制到

Server.MapPath("~") + @"Files\Docx\"以“D210”命名。

如何复制此文件并重命名?

4

1 回答 1

4

你需要做 IO 工作所以不要忘记添加Using System.IO;
,这是你需要的代码:

//1.Prepare the name for renaming
string newName = "D210";

//2.Create the Folder if it doesn't already exist
if(!Directory.Exists(Server.MapPath("~")+@"\Files\Docx\"))
    Directory.CreateDirectory(Server.MapPath("~")+@"\Files\Docx\");

//3.Copy the file with the new name
File.Copy(Server.MapPath("~") + @"Files\tmp.docx",Server.MapPath("~")+@"\Files\Docx\"+newName+".docx");
于 2012-12-15T10:29:36.100 回答