.net - how to save image in database -


fileupload img = (fileupload)uploadimg;         byte[] imgbyte = null;         if (img.hasfile && img.postedfile!=null)         {             httppostedfile file = uploadimg.postedfile;             imgbyte = new byte[file.contentlength];             file.inputstream.read(imgbyte, 0, file.contentlength);         }    **strong text** 

here want save image in database . want convert image byte array. wrote above code. here if condition not executed

assuming have file upload control on page:

<asp:fileupload id="uploadimg" runat="server" /> <asp:button id="uploadbutton" runat="server" text="upload" onclick="uploadbutton_click" /> 

the following should work:

protected void uploadbutton_click(object sender, eventargs e) {     if(uploadimg.hasfile)     {         byte[] imgbyte = uploadimg.filebytes;         string filename = path.getfilename(uploadimg.filename);         // todo: save image database     } } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -