All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP截取UTF-8字符串,解决半字符问题_php资料_编程技术
问题“未于信任SQL,Server连接相关联”的解决_[SQL,Server教程]
利用DataGrid显示某目录下的所有文件_[Asp.Net教程]
整站如何防止SQL注入攻击_[Asp.Net教程]
.NET访问配置文件app.config的功能详解_.net资料_编程技术
在asp.net页面中使用异步读取_.net资料_编程技术
文字链接技术基础_JavaScript技术_编程技术
C#,3.0新特性初步研究,Part6:使用查询表达式_[Asp.Net教程]
HTML 初学者指南(1)_[Html教程]
PHP编程中操作目录和文件总结_[PHP教程]
Reading number is top 10 pictures
[猫扑大杂烩]华东师范墙上看到的捐精告示 15毫升3600元
如果没有好报,为什么要做好人?
A man's favorite things16
Embarrassing things comic collection2
这张图有两句话,你看出来了吗?
BingBingFan apple dew point photo gallery1
无题
Thrilling English baby
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line1
擦地板的大叔太好了
Download software ranking
Kung fu panda - the secret of the teacher
Tram sex maniac 2 (H) rar bag19
The Bermuda triangle2
Boxer Classic video2
SP4 for SQL2000
中国结婚习俗实录
Call Of Duty2
Boxer vs Yellow4
Eclipse 4.2.2 For Win32
Unix video tutorial5
delv published in(发表于) 2014/1/24 9:03:50 Edit(编辑)
asp.net2.0实现文件上传,控制上传文件大小,类型_[Asp.Net教程]

asp.net2.0实现文件上传,控制上传文件大小,类型_[Asp.Net教程]

asp.net2.0实现文件上传,控制上传文件大小,类型_[Asp.Net教程]

1、建立Default.aspx文件和文件夹upLoad

2、Default.aspx代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页






onClick="Button1_Click" Text="上传" Width="44px" />

上传文件名:

上传文件大小:

上传文件路径及名:










3、Default.aspx.cs代码如下:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{

Label2.Text = FileUpload1.FileName;
Label3.Text = FileUpload1.PostedFile.ContentLength.ToString() + "字节";
Label4.Text = FileUpload1.PostedFile.FileName;
//获得扩展名
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (extension == ".rar" || extension == ".doc" || extension == ".xls")
{

if (FileUpload1.PostedFile.ContentLength < 10000000)//文件小于10M
{
FileUpload1.SaveAs(Server.MapPath("~/upLoad/" + FileUpload1.FileName));
Label1.Text = "恭喜你,上传成功!";
}
else
{
Label1.Text = "上传失败,不是管理员,上传文件不能大于10M!";
}
}
else
Label1.Text = "上传失败,只能上传扩展名是rar、doc、xls的文件!";
}
else
{
Label1.Text = "上传失败,或没指定正确的文件!";
}
}
}



4:运行效果如下:







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.