asp.net - display uploded image in image control -


i want upload image folder in website's folder , save it's path database , display uploaded image in control image. when executed page image uploaded succefully , it's saved database dosent displayed on image control.

this view :

<%@ page language="vb" autoeventwireup="false" codefile="default.aspx.vb" inherits="_default" %>  <!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>      </div>     <asp:fileupload id="fileupload1" runat="server" />     <asp:button id="button1" runat="server" text="button" />     <asp:image id="image1" runat="server" height="91px" width="145px" />     </form>      <p>         &nbsp;</p>  </body> </html> 

and code :

imports system.data.sqlclient imports system.io imports system.data  partial class _default     inherits system.web.ui.page     dim cn sqlconnection      protected sub button1_click(byval sender object, byval e system.eventargs) handles button1.click         if fileupload1.postedfile isnot nothing             dim filename string = path.getfilename(fileupload1.postedfile.filename)              'save files disk             fileupload1.saveas(server.mappath("~/im/" & filename))              'add entry database              dim strquery string = "insert dbo.images" & " values(@filename, @filepath)"             dim cmd new sqlcommand(strquery)             cmd.parameters.addwithvalue("@filename", filename)             cmd.parameters.addwithvalue("@filepath", "~/im/" & filename)             cmd.commandtype = commandtype.text             cmd.connection = cn              try                 cn.open()                 cmd.executenonquery()              catch ex exception                 response.write(ex.message)                              cn.close()                 cn.dispose()             end try         end if     end sub      protected sub page_load(byval sender object, byval e system.eventargs) handles me.load         cn = new sqlconnection("server=sevo-pc;initial catalog=controle;integrated security=true")     end sub      protected sub fileupload1_load(byval sender object, byval e system.eventargs) handles fileupload1.load         image1.imageurl = "im/" & fileupload1.filename      end sub end class 

try following edit

protected sub fileupload1_load(byval sender object, byval e system.eventargs) handles fileupload1.load         image1.imageurl = server.mappath("/im/") & fileupload1.filename      end sub 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -