NinetyNine's Treasure

| 积淀*育创新 智慧创造价值|

导航

多文件上传

Posted on 2007-09-15 13:12  (NineTyNine)  阅读(486)  评论(0编辑  收藏  举报
页面中添加了三个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);
                    }

                }

            }


        }