| 发表于:2007-04-17 17:06:04 楼主 |
<%@ page language= "c# " autoeventwireup= "true " codefile= "loadimg_test.aspx.cs " inherits= "manage_loadimg_test " %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en " "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd "> <html xmlns= "http://www.w3.org/1999/xhtml " > <head runat= "server "> <title> 无标题页 </title> </head> <body> <form id= "form1 " runat= "server "> <div> <asp:scriptmanager id= "scriptmanager1 " runat= "server "> </asp:scriptmanager> <asp:updatepanel id= "updatepanel1 " runat= "server "> <contenttemplate> <asp:image id= "image_move " runat= "server " height= "336px " width= "643px " imageurl= "~/images/upimg/1.bmp " /> <br /> <div> <asp:fileupload id= "fileupload_move " runat= "server " /> <asp:button id= "btn_upload " runat= "server " text= "上传 " width= "59px " onclick= "btn_upload_click " /> <br /> <asp:label id= "label1 " runat= "server " text= "label "> </asp:label> </div> </contenttemplate> </asp:updatepanel> <br /> </div> </form> </body> </html> using system; using system.data; using system.configuration; using system.collections; using system.web; using system.web.security; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.webcontrols.webparts; using system.web.ui.htmlcontrols; public partial class manage_loadimg_test : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void btn_upload_click(object sender, eventargs e) { boolean fileok=false; string name=this.fileupload_move.filename; //string size=this.fileupload_move.postedfile.contentlength.tostring(); //string type=this.fileupload_move.postedfile.contenttype; //string type2; string ipath = server.mappath( "~/images/upimg/ "+name); //string fpath = server.mappath( "~/images/upfile/ "+name); //string wpath = "~/images/upimg/ " + name; if (this.fileupload_move.hasfile) { string fileextension = system.io.path.getextension(this.fileupload_move.filename).tolower(); string[] allowedextensions ={ ".gif ", ".png ", ".jpeg ", ".jpg ", ".bmp "}; for (int i = 0; i < allowedextensions.length; i++) { if (fileextension == allowedextensions[i]) { fileok = true; } } if (fileok) { try { this.fileupload_move.postedfile.saveas(ipath); this.image_move.imageurl = "~/images/upimg/ "+name; this.label1.text= "上传成功! "; } catch { this.label1.text = "上传失败! "; } } } } } |
|
|
|
|