没有合适的资源?快使用搜索试试~ 我知道了~
C#上传控件
4星 · 超过85%的资源 需积分: 10 44 下载量 16 浏览量
2012-06-01
12:44:00
上传
评论
收藏 2KB TXT 举报
温馨提示
试读
2页
C#上传控件FileUpload的设置,能够顺利上传东西。
资源推荐
资源详情
资源评论
(1)关于FileUpload控件上传文件大小限制问题:
在web.config的system.web节中添加:
<httpRuntime maxRequestLength="512000" executionTimeout="120" />
maxRequestLength指示 ASP.NET 支持的最大文件上载大小。该限制可用于防止因用户将大量文件传递到该服务器而导致的拒绝服务攻击。指定的大小以 KB 为单位。默认值为 4096 KB (4 MB)。
executionTimeout 指示允许执行请求的最大时间,以秒为单位,默认90秒。
(2)上传控件代码:
public Boolean upfile()
{
if (FileUpload1.PostedFile.ContentLength > 0)
{
string nam = FileUpload1.PostedFile.FileName;
int i = nam.LastIndexOf(".");
string newext = nam.Substring(i);
if (newext == ".txt" || newext == ".jpg" || newext == ".pdf" || newext == ".rar" || newext == ".zip")
{
DateTime now = System.DateTime.Now;
string newname = now.DayOfYear.ToString() + now.Minute.ToString() + now.Second.ToString()
+ FileUpload1.PostedFile.ContentLength.ToString();
FileUpload1.PostedFile.SaveAs(("F:/IBM") + "\\" + newname + newext);
//FileUpload1.PostedFile.SaveAs(Server.MapPath("../Image") + "\\" + newname + newext);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('只能上传txt或jpg或pdf或rar或zip');</script>");
}
在web.config的system.web节中添加:
<httpRuntime maxRequestLength="512000" executionTimeout="120" />
maxRequestLength指示 ASP.NET 支持的最大文件上载大小。该限制可用于防止因用户将大量文件传递到该服务器而导致的拒绝服务攻击。指定的大小以 KB 为单位。默认值为 4096 KB (4 MB)。
executionTimeout 指示允许执行请求的最大时间,以秒为单位,默认90秒。
(2)上传控件代码:
public Boolean upfile()
{
if (FileUpload1.PostedFile.ContentLength > 0)
{
string nam = FileUpload1.PostedFile.FileName;
int i = nam.LastIndexOf(".");
string newext = nam.Substring(i);
if (newext == ".txt" || newext == ".jpg" || newext == ".pdf" || newext == ".rar" || newext == ".zip")
{
DateTime now = System.DateTime.Now;
string newname = now.DayOfYear.ToString() + now.Minute.ToString() + now.Second.ToString()
+ FileUpload1.PostedFile.ContentLength.ToString();
FileUpload1.PostedFile.SaveAs(("F:/IBM") + "\\" + newname + newext);
//FileUpload1.PostedFile.SaveAs(Server.MapPath("../Image") + "\\" + newname + newext);
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('只能上传txt或jpg或pdf或rar或zip');</script>");
}
资源评论
- k11845359142014-12-14具有不错的参考性。
- systemlover2012-12-24虽然最后没用你的,但还是谢谢。
wwweet
- 粉丝: 58
- 资源: 195
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功