请问如何自定义Fileupload 附件大小,最近发现附件太大的话,就会显示无法显示网页,请问该如何解决?谢谢!!
另:这是我的上传代码,2个问题请教:1、请问如何改才能实现大文件的上传 2、如果文献格式不是我指定的,就提示格式有错误即可,下面的“添加”代码(insert into wenjian (wjname,author,keywords,mulu,datetime,location)values(@wjname,@author,@keywords,@mulu,@datetime,@location)";
)就不要执行了,即信息就不要添加到数据库里去了。谢谢哦
try
        {
            //获取文件夹路径
            string Fullname = this.FileUpload1.FileName;
            string Type = Fullname.Substring(Fullname.LastIndexOf(".") + 1);
            string FilePath = Server.MapPath("./") + "File" + "\\" + Fullname;
            
            if (Type == "pdf" || Type == "doc" || Type == "xls" || Type == "txt" || Type == "jpg" || Type == "JPG" || Type == "gif" || Type == "bmp" || Type == "rar" || Type == "zip" || Type == "dwg")
            {
                this.FileUpload1.SaveAs(Server.MapPath("File") + "\\" + Fullname);            }
            else
            {
                Response.Write("<script language='javascript'>alert('你上传的文献格式有错误!');window.location.href='upfile.aspx';</script>");
            }
           
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server=(local);uid=sa;pwd=sa;database=wenjian;";
            con.Open();            SqlCommand cmd = new SqlCommand();
            cmd.Connection = (SqlConnection)con;
            cmd.CommandText = "insert into wenjian (wjname,author,keywords,mulu,datetime,location)values(@wjname,@author,@keywords,@mulu,@datetime,@location)";
            cmd.Parameters.Add("@wjname", SqlDbType.VarChar);
            cmd.Parameters.Add("@author", SqlDbType.Char);
            cmd.Parameters.Add("@keywords", SqlDbType.VarChar);
            cmd.Parameters.Add("@mulu", SqlDbType.VarChar);
            cmd.Parameters.Add("@datetime", SqlDbType.DateTime);
            cmd.Parameters.Add("@location", SqlDbType.VarChar);            cmd.Parameters["@wjname"].Value = this.Texname.Text;
            cmd.Parameters["@author"].Value = this.Texauthor.Text;
            cmd.Parameters["@keywords"].Value = this.Texkeywords.Text;
            cmd.Parameters["@mulu"].Value = this.muluID.SelectedItem.Text;
            cmd.Parameters["@datetime"].Value = Convert.ToString(DateTime.Today.ToShortDateString());
            cmd.Parameters["@location"].Value = FilePath.ToString();            cmd.ExecuteNonQuery();
            con.Close();            Response.Write("<script language='javascript'>alert('添加成功!')</script>");            this.Texname.Text = "";            Texauthor.Text = "";
            Texkeywords.Text = "";
        }
     
        catch (Exception ex)
        { Response.Write(ex.Message); }

解决方案 »

  1.   

    1、设置web.config中httpRuntime配置节的maxRequestLength 属性值,默认值为4096 KB,即4M,详细说明请看这里:http://msdn.microsoft.com/en-us/library/e1f13641(VS.71).aspx2、把你向数据库中插入数据的代码放在上面的if那个判断文件后缀的条件中即可。
      

  2.   

    <httpRuntime maxRequestLength="500000"/>
      

  3.   

    1、请问如何改才能实现大文件的上传
    回答:在web.config文件里面的<system.web>添加: <system.web>
            <httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
      </system.web>
    2、如果文献格式不是我指定的,就提示格式有错误即可else
                {
                    Response.Write(" <script language='javascript'>alert('你上传的文献格式有错误!'); window.location.href='upfile.aspx'; </script>");
                    return;//加这个
                } 
      

  4.   

    对了 现在又发现一个问题,就是当我上传大文件时,上传的时间等的会比较久,请问可以这个可以设置吗?我将executionTimeout的时间改小了貌似也不行,再请教各位高手,谢谢
      

  5.   

    <system.web>
    </system.web>在这个节点下配置,可以控制上传文件的大小有兴趣共同学习得人请加群:88718955 讨论C#,asp.net,Java,J2EE,JavaScript,Jquery,ext等