您目前尚未登陆,请选择【登陆】或【注册
首页->功能源码->Web图片管理系统代码>>Upload.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Web图片管理系统代码
当前文件:文件类型 PictureManager/Upload.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11 12public partial class Upload : System.Web.UI.Page 13{ 14 SQLHelper helper = new SQLHelper(); 15 protected void Page_Load(object sender, EventArgs e) 16 { 17 if (!IsPostBack) 18 { 19 if (Request.Params["ImgID"] != null) 20 { 21 btnUploadPic.Enabled = true; 22 ViewState["ImgID"] = Request.Params["ImgID"].ToString(); 23 } 24 else 25 { 26 btnUploadPic.Enabled = false; 27 ViewState["ImgID"] = ""; 28 } 29 } 30 31 } 32 protected void btnUploadPic_Click(object sender, EventArgs e) 33 { 34 if (!tbxPicPath.HasFile) 35 { 36 Response.Write("<script>window.alert('请指定上传路径!')</script>"); 37 return; 38 } 39 else if (tbxPicPath.PostedFile.ContentLength == 0) 40 { 41 Response.Write("<script>window.alert('文件的内容不能为空!')</script>"); 42 return; 43 } 44 45 // 获取上传图片的文件名 46 String fileName = tbxPicPath.PostedFile.FileName.Substring(tbxPicPath.PostedFile.FileName.LastIndexOf("\\")); 47 48 if (System.IO.File.Exists(Server.MapPath(Request.ApplicationPath) + "\\Pictures" + fileName)) 49 { 50 Response.Write("<script>window.alert('该文件名在服务器中已存在,请更改文件名!')</script>"); 51 } 52 else 53 { 54 try 55 { 56 // 上传文件 57 tbxPicPath.PostedFile.SaveAs(Server.MapPath(Request.ApplicationPath) + "\\Pictures" + fileName); 58 // 添加数据库信息 59 helper.addNode(tbxPicName.Text.Trim(), Request.ApplicationPath + "\\Pictures" + fileName, "0", ViewState["ImgID"].ToString()); 60 // 显示上载成功的信息 61 Response.Write("<script>window.alert('文件上传成功!')</script>"); 62 } 63 catch (Exception ex) 64 { 65 Response.Write("<script>window.alert('由于网络原因,上载文件错误 " + ex.Message + "')</script>"); 66 } 67 68 tbxPicName.Text = ""; 69 } 70 } 71 protected void btnReturn_Click(object sender, EventArgs e) 72 { 73 Response.Redirect("~/List.aspx"); 74 } 75} 76
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:Web图片管理系统代码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号