protected void btn_Upload_Click(object sender, EventArgs e) { string serverPath = Server.MapPath("Upload"); if (!System.IO. ...
protected void btn_Upload_Click(object sender, EventArgs e) { get='_blank'>string serverPath = Server.MapPath("Upload"); if (!System.IO.Directory.Exists(serverPath))//判断文件的目录是否存在 { System.IO.Directory.CreateDirectory(serverPath);//如果文件目录不存在,创建文件目录 } if (file_upload.HasFile)//判断是否选择了控件 { int fileSize = this.file_upload.PostedFile.ContentLength / 1024 / 1024;//获取上传文件的大小 if (fileSize > 8)//如果上传文件的大小大于8兆 { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('只允许上传小于8兆的文件')", true); return; } else { file_upload.SaveAs(serverPath + "\\" + file_upload.FileName);//文件保存到服务器的指定目录下 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('上传文件成功!!')",true); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择要上传的文件')", true); return; } }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:上传文件控件的使用
关键词:上传
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。