会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Web.网际浪人.Blog
【没有最完美的解决方案,只有最适合的解决方案——Karl He】
博客园
首页
新随笔
联系
订阅
管理
asp.net 2.0 上传控件的使用
试用了一下asp.net 2.0的上传控件,还是挺方便的。 分享代码
试用了一下asp.net 2.0的上传控件,还是挺方便的。
分享代码如下:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
try
{
判断文件大小
#region
判断文件大小
int
intFileLength
=
this
.FileUpload1.PostedFile.ContentLength;
if
(intFileLength
>
50000
)
{
this
.Label1.Text
=
"
文件大于50k,不能上传
"
;
return
;
}
#endregion
判断保存的文件夹是否存在
#region
判断保存的文件夹是否存在
string
strUpPath
=
@"
upfile\
"
+
System.DateTime.Now.ToShortDateString();
//
+@"\";
//
文件夹不存在的时候,创建文件夹
if
(
!
System.IO.Directory.Exists(Server.MapPath(strUpPath)))
{
System.IO.Directory.CreateDirectory(Server.MapPath(strUpPath));
}
string
strUrl
=
Server.MapPath(strUpPath
+
@"
\
"
+
this
.FileUpload1.FileName);
#endregion
//
上传文件
this
.FileUpload1.SaveAs(strUrl);
this
.Label1.Text
=
"
文件上传成功
"
;
}
catch
(System.Exception ex)
{
this
.Label1.Text
=
"
文件上传失败:
"
+
ex.Message;
}
}
示例工程:
/Files/heekui/WebUpLoad.rar
posted on
2006-12-23 01:54
网际浪人
阅读(
504
) 评论(
0
)
收藏
举报
刷新页面
返回顶部