页面中添加了三个File控件
private void Button1_Click(object sender, System.EventArgs e)
{
if(this.File1.PostedFile.FileName==""&&this.File2.PostedFile.FileName==""&&this.File3.PostedFile.FileName=="")
{
this.lbl_info.Text="请输入文件";
}
else
{
HttpFileCollection myFiles=Request.Files;
for(int i=0;i<myFiles.Count;i++)
{
HttpPostedFile myPost=myFiles[i];
try
{
if(myPost.ContentLength>0)
{
string filepath=myPost.FileName;
string filename=filepath.Substring(filepath.LastIndexOf("\\")+1);
string serverpath=Server.MapPath("images/")+filename;
myPost.SaveAs(serverpath);
this.lbl_info.Text="上传成功";
}
}
catch(Exception error)
{
Response.Write("你的错误原因:"+error.Message);
}
}
}
}
{
if(this.File1.PostedFile.FileName==""&&this.File2.PostedFile.FileName==""&&this.File3.PostedFile.FileName=="")
{
this.lbl_info.Text="请输入文件";
}
else
{
HttpFileCollection myFiles=Request.Files;
for(int i=0;i<myFiles.Count;i++)
{
HttpPostedFile myPost=myFiles[i];
try
{
if(myPost.ContentLength>0)
{
string filepath=myPost.FileName;
string filename=filepath.Substring(filepath.LastIndexOf("\\")+1);
string serverpath=Server.MapPath("images/")+filename;
myPost.SaveAs(serverpath);
this.lbl_info.Text="上传成功";
}
}
catch(Exception error)
{
Response.Write("你的错误原因:"+error.Message);
}
}
}
}