用asp.net 实现类似邮件附件上传的效果 
可以选多个文件 不满意可以删除一两个 点击发送 才吧文件上传到服务器上 用FileUpload只能实现单文件上传 如果多文件上传需要多个FileUpload控件 这样感觉效果 不是很号
所以 想 弄个 类似QQ邮箱的多附件上传的 样子 但是不知道 怎么弄希望 各位大虾 能帮一下 小弟!

解决方案 »

  1.   

    protected bool upMorefile()
        {
            
            //遍历File表单元素
            System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
            //状态信息
            System.Text.StringBuilder strMsg = new System.Text.StringBuilder("成功上传的文件信息分别为:<hr color=red>");
            int fileCount;
            int filecount = files.Count;
            
           
            try
            {
                for (fileCount = 0; fileCount < files.Count; fileCount++)
                {
                    //定义访问客户端上传文件的对象
                    System.Web.HttpPostedFile postedFile = files[fileCount];
                    string FileType = postedFile.ContentType.ToString();//获取要上传的文件类型,验证文件头                  string fileName, fileExtension;
                    //取得上传得文件名
                    fileName = System.IO.Path.GetFileName(postedFile.FileName);
                    //取得文件的扩展名
                    fileExtension = System.IO.Path.GetExtension(fileName);                //在上传文件不为空的情况下,验证文件名以及大小是否符合,如果不符合则不允许上传
                    if (((FileType == "text/plain" && fileExtension.ToLower() == ".txt") || (FileType == "application/x-zip-compressed" && fileExtension.ToLower() == ".zip") || (FileType == "application/octet-stream" && fileExtension.ToLower() == ".rar"))&&postedFile.ContentLength/1024<=1024)
                    {//在这里通过检查文件头与文件名是否匹配 从而限制了文件上传类型  注:可上传的类型有TXT,ZIP,RAR,且大小只能为1M一下
                        
                        if (fileName != String.Empty)
                        {
                            fileName = RandomFileName() + fileExtension;
                            
                            //上传的文件信息
                            strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
                            strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
                            strMsg.Append("上传文件的文件名:" + fileName + "<br>");
                            strMsg.Append("上传文件的大小为:" + postedFile.ContentLength + "字节<br>");
                            strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");
                            //保存到指定的文件夹
                            postedFile.SaveAs(Server.MapPath("public_file/" + UserName + "/") + fileName);
                            fileName = "";                    }
                    }
                    else
                    {
                        strStatus.Text+= "第"+(fileCount+1)+"个文件不符合要求<br/>  ";
                        
                    }
                    
                }
                
                strStatus.Text += strMsg.ToString();
                return true;
            }
            catch (System.Exception error)
            {
                strStatus.Text = error.Message;
                return false;        }
        }