試用了一下asp.net 2.0的上傳控件,還是挺友善的。
分享代碼如下:
asp.net 2.0 上傳控件的使用 protected void Button1_Click(object sender, EventArgs e)
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 {
asp.net 2.0 上傳控件的使用 try
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 判斷檔案大小#region 判斷檔案大小
asp.net 2.0 上傳控件的使用 int intFileLength = this.FileUpload1.PostedFile.ContentLength;
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 if (intFileLength > 50000)
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 this.Label1.Text = "檔案大于50k,不能上傳";
asp.net 2.0 上傳控件的使用 return;
asp.net 2.0 上傳控件的使用 }
asp.net 2.0 上傳控件的使用 #endregion
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 判斷儲存的檔案夾是否存在#region 判斷儲存的檔案夾是否存在
asp.net 2.0 上傳控件的使用 string strUpPath = @"upfile\" + System.DateTime.Now.ToShortDateString();// +@"\";
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 //檔案夾不存在的時候,建立檔案夾
asp.net 2.0 上傳控件的使用 if (!System.IO.Directory.Exists(Server.MapPath(strUpPath)))
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 System.IO.Directory.CreateDirectory(Server.MapPath(strUpPath));
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 string strUrl = Server.MapPath(strUpPath + @"\" + this.FileUpload1.FileName);
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 //上傳檔案
asp.net 2.0 上傳控件的使用 this.FileUpload1.SaveAs(strUrl);
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 this.Label1.Text = "檔案上傳成功";
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 }
asp.net 2.0 上傳控件的使用 catch (System.Exception ex)
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 this.Label1.Text = "檔案上傳失敗:" + ex.Message;
asp.net 2.0 上傳控件的使用
asp.net 2.0 上傳控件的使用 }