请问如何自定义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); }
另:这是我的上传代码,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); }
回答:在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;//加这个
}
</system.web>在这个节点下配置,可以控制上传文件的大小有兴趣共同学习得人请加群:88718955 讨论C#,asp.net,Java,J2EE,JavaScript,Jquery,ext等