试用了一下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;
}
}
作者:gdgzboy@牛C网
地址:http://www.niuc.net/post/2136/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
利用RowFilter属性,将一个DataSet绑定到两个DataGrid
ADO.NET中的视图和过滤器
在ASP.NET中值得注意的两个地方
.NET中突破每客户端两个http连接的限制
.NET家族新成员-G#语言简介
ASP.net的ACCESS数据分页方案
用ASP.NET设计优秀系统
.NET下的动态代码编译探索
从资源文件中取图片
使用AdminScripts脚本创建虚拟目录
关于ASP.NET调用JavaScript的实现
asp.net 2.0 中加密web.config 文件中的配置节





