.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
Post a Comment