我使用 ASP.net 并在网站上有一个 .docx 文件:
Server.MapPath("~") + @"Files\tmp.docx".
我想将此文件复制到
Server.MapPath("~") + @"Files\Docx\"
以“D210”命名。
如何复制此文件并重命名?
我使用 ASP.net 并在网站上有一个 .docx 文件:
Server.MapPath("~") + @"Files\tmp.docx".
我想将此文件复制到
Server.MapPath("~") + @"Files\Docx\"
以“D210”命名。
如何复制此文件并重命名?
你需要做 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");