ASP .net 实现文件上传 下载功能
一、文件上传
1、单文件上传
利用FileUpload控件完成上传功能
代码:
string filepath = FileUpload1.PostedFile.FileName;
string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
string serverpath = Server.MapPath("File/") + filename;
FileUpload1.PostedFile.SaveAs(serverpath);
2、多文件上传
代码:
string FilePath = Server.MapPath("./") + "File";
HttpFileCollection HFC = Request.Files;
for (int i = 0; i < HFC.Count; i++)
{
HttpPostedFile UserHPF = HFC[i];
try
{
if (UserHPF.ContentLength > 0)
{
UserHPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(UserHPF.FileName));
}
&
ASP .net 实现文件上传 下载功能
最新推荐文章于 2021-11-11 10:17:11 发布