asp.net单个文件上传和多个文件上传
单个文件
.aspx
<input type="file" id="UploadFile" name="UploadFile" runat="server" />
.cs
string sPath = Server.MapPath("~") + @"\upload\file\;
string FileName = "filename.txt";
UploadFile.PostedFile.SaveAs(sPath + FileName);
多个文件
.aspx
<input type="file" id="UploadFile" name="UploadFile" runat="server" />
<input type="file" id="File1" name="UploadFile" runat="server" />
.cs
HttpFileCollection files = Request.Files;
string sPath = Server.MapPath("~") + @"\upload\file\;
string FileName = string.Empty;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string Sheet = "file" + System.DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", "") + "-" + i.ToString();
FileName = Sheet + ".xls";
file.SaveAs(sPath + FileName);
}