如题

解决方案 »

  1.   

    if (FileUpload1.PostedFile.ContentLength < 1024 * 2000)
                {}
      

  2.   

    我用调试跟踪,他没有进判断就直接弹出进度条开始传了,莫名,代码如下:protected void btnSubmit_Click(object sender, EventArgs e)
            {
                //验证填写是否通过
                if (Vaildate())
                {
                    Dictionary<string, string> dic = (Dictionary<string, string>)Session["Evidence"];
                    string fileName = AttachFile.FileName;//获取文件名
                    string extenName = System.IO.Path.GetExtension(fileName);//获取扩展名
                    string saveFileName = System.IO.Path.Combine(Request.PhysicalApplicationPath + "UploadTemp", DateTime.Now.ToString("yyyyMMddhhmm") + extenName);//合并两个路径为上传到服务器上的全路径
                    //判断是否已存在相同文件名
                    if (dic.ContainsKey(fileName))
                    {
                        Response.Write("<script>alert('已存在同名文件');</script>");
                    }
                    else
                    {
                        try
                        {
                            AttachFile.MoveTo(saveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        dic.Add(fileName, saveFileName);
                        Session["Evidence"] = dic;                    //传递本页面的返回值
                        string strScript = string.Empty;
                        strScript += "<script language='javascript'> ";
                        strScript += " window.returnValue='true'";
                        strScript += "</script>";
                        ClientScript.RegisterStartupScript(this.GetType(), "KK", strScript);
                        ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>window.close();</script>");
                    }
                }
            }        /// <summary>
            /// 验证表单填写是否规范
             /// </summary>
            /// <returns></returns>
            protected bool Vaildate()
            {
                if (AttachFile.HasFile)
                {
                    //文件名
                    string fileName = AttachFile.FileName;
                    //文件后缀名
                    string postfix = System.IO.Path.GetExtension(fileName).ToLower();                //判断文件大小
                    if (AttachFile.ContentLength > 10240000)
                    {
                        Response.Write("<script>alert('文件大小超出范围');</script>");
                        return false;
                    }
                    return true;
                }
                Response.Write("<script>alert('尚未选取附件');</script>");
                return false;
            }
      

  3.   


    //获取文件大小并保留小数点后一位,单位是M
    float FileSize = (float)System.Math.Round((float)AttachFile.ContentLength / 1024000, 1); 
      

  4.   

    我用调试跟踪,他没有进判断就直接弹出进度条开始传了!难道是我在WEB.CONFIG里配置有误?
      

  5.   

    可能我描述的不够清楚,我再解释下
    在AttachFile.MoveTo(saveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite); 也就是上传文件之前,我加了判断控制文件的大小,但是我跟踪调试:点击上传BUTTON后,还没有执行到判断,ProgressBar就已经弹出来并且开始上传,显示进度了,如何让这个ProgressBar在判断执行之后,再开始上传?
      

  6.   

    我也遇到了同样的问题,这个要在web.config中配置maxRequestLength,如果大于你设定的值,那么进度条显示rejected  <neatUpload ... useHttpModule="false" maxNormalRequestLength="100" maxRequestLength="2097151">详细的信息你可以参照neatupload网站提供的手册:http://www.brettle.com/NeatUpload-1.3/dotnet/docs/Manual.html#3.4.Allowing%20Users%20with%20Flash%20to%20Select%20Multiple%20Files%20from%20One%20File%20Selection%20Dialog|outline
      

  7.   

    计算有错误哦,应该是:
    float FileSize = (float)System.Math.Round((float)AttachFile.ContentLength / 1024000, 1);
    点击文件,查看属性,可以看到文件大小是以字节计算的,1M=1024KB,1KB=1024字节
      

  8.   

    在你的 Button 上写一个 onmousedown 的功能
    用JavaScript判断  如果不满足条件则return false; 这样就不会提交到后台