asp.net 2.0 上传控件的使用
点击次数:22 次 发布日期:2008-11-26 11:32:17 作者:源代码网
|
源代码网推荐 源代码网推荐 分享代码如下: 源代码网推荐 源代码网推荐 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; 源代码网推荐 } 源代码网推荐 } 源代码网推荐 示例工程: http://www.cnblogs.com/Files/heekui/WebUpLoad.rar 源代码网推荐 源代码网推荐 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
