1,前台页面部分
2,后台代码部分
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
public const string StatusChangeFilePath = "StatusChangeFile/"; //附件保存地址
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpLoad_Click(object sender, EventArgs e)
{
string sFilesName = "";
HttpPostedFile oPostedFile;
int n = 0;
n = Request.Files.Count;
for (int i = 0; i < n; i++)
{
oPostedFile = Request.Files.Get(i);
sFilesName = UpLoadMoreFile(oPostedFile, StatusChangeFilePath);
lblError.Text = "上传成功";
}
}
private string UpLoadMoreFile(HttpPostedFile Postfile, string Path)
{
string fileName = "";
if (Postfile.FileName == "")
{
return "";
}
else
{
fileName = Postfile.FileName;
fileName = fileName.Substring(fileName.LastIndexOf("//"), fileName.Length - fileName.LastIndexOf("//"));
Postfile.SaveAs(Server.MapPath(Path + fileName));
return "成功";
//Postfile.cu
}
}
}
之前,我们介绍过一篇asp.net 多文件上传的例子,有需要的朋友,也可以参考下。