如何重命名在ASP.NET文件? [英] How can I rename a file in ASP.NET?

查看:219
本文介绍了如何重命名在ASP.NET文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,我想这是在更新前重命名文件。例如,在我的系统文件,比如 Mycontact.xls 。我想将其重命名为 sasi.xls (这是一个excel文件)。我怎么能写code在ASP.NET?

In my project I want to rename the file before it is updating. For example a file in my system like Mycontact.xls. I want to rename it as sasi.xls (it is an excel file). How can I write the code in ASP.NET?

其实我使用一个FileUpload控件获取在文件和重命名文件并上传这是在的解决方案资源管理

Actually I am using a fileupload control to get the file in and rename the file and upload the renamed file in a folder which is in Solution Explorer.

推荐答案

C#不提供文件重命名功能,很遗憾。总之,这个想法是要做到这一点:

C# does not provide a file rename function, unfortunately. Anyhow, the idea is to do this:

File.Copy(oldFileName, NewFileName);

File.Delete(oldFileName);

您也可以使用 - File.Move

You can also use - File.Move.

这篇关于如何重命名在ASP.NET文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆