string str = File1.PostedFile.FileName;
if (str == "")
{
Response.Write("<script>alert('请输入上传文件的名字')</script>");
return;
//this.Label1.Text = "请输入文件名";
}
else
{
string ss = str.Substring(str.LastIndexOf("\\") + 1);
string s = Server.MapPath("~\\images\\" + ss);
//path = "~\\images\\" + ss;
if (File.Exists(s))
{
Response.Write("该文件已经存在,请重新命名!!!");
return;
}
this.File1.PostedFile.SaveAs(s);
Response.Write("上传成功!");
}
这是我的上传button中设置的代码,请问我该如何去限制上传文件的长度?
if (str == "")
{
Response.Write("<script>alert('请输入上传文件的名字')</script>");
return;
//this.Label1.Text = "请输入文件名";
}
else
{
string ss = str.Substring(str.LastIndexOf("\\") + 1);
string s = Server.MapPath("~\\images\\" + ss);
//path = "~\\images\\" + ss;
if (File.Exists(s))
{
Response.Write("该文件已经存在,请重新命名!!!");
return;
}
this.File1.PostedFile.SaveAs(s);
Response.Write("上传成功!");
}
这是我的上传button中设置的代码,请问我该如何去限制上传文件的长度?
in length=this.FileUpload1.PostedFile .ContentLength 这个可以获取到上传文件的大小
if(length>"1024")
{
....
}
1024指的是kB