protected void btnSave_Click(object sender, EventArgs e)
{
string savePath = Server.MapPath("/Upload");//保存的路径
if (FileUpload1.HasFile)
{
try
{
string fileName = Server.HtmlEncode(FileUpload1.FileName);
string extension = Path.GetExtension(fileName);//获得后缀
if (FileUpload1.PostedFile.ContentLength > 100000)//文件大小限制
{
lblPic.Text = "文件不能超过100K";
return;
}
if ((extension == ".jpg") || (extension == ".gif") || (extension == ".png") || (extension == ".jpeg"))
{
FileUpload1.SaveAs(savePath + fileName);
}
else
{
lblPic.Text = "限上传:gif,jpg,jpeg,png格式的图片";
return;
}
}
catch (Exception ex)
{
//
}
}
中<system.web>中加入
<httpRuntime executionTimeout="90" maxRequestLength="200000" useFullyQualifiedRedirectUrl="false" />
上传是先校验这里的大小的。默认最大为4M。上传超过此大小的就会报错了。
相关新闻
- 小程序登录流程图理解 2020-08-18
- 在C#中获取web.config中的配置信息 2021-08-23
- 小程序open-data头像样式 2021-04-10
- 小程序rich-text 富文本解析图片过大和图片路径的问题 2020-11-25
- C#中去掉字符串的最后一个字符 2020-11-23