asp.net - Error in converting base64 string to image c# -


i want display image on web page , while clicking link button should download. image file stored stored binary format in db. while converting base64 string image showing error. details given below. me find proper solution. thank you.

error:

enter image description here

code:

 protected void page_load(object sender, eventargs e)   {    if (!ispostback)      {        pdfdatasettableadapters.tbl_imgtableadapter td;       td = new pdfdatasettableadapters.tbl_imgtableadapter();       datatable dt = new datatable();       dt = td.getid();       dropdownlist1.datasource = dt;       dropdownlist1.datatextfield = "id";       dropdownlist1.datavaluefield = "id";       dropdownlist1.databind();       dropdownlist1.items.insert(0, new system.web.ui.webcontrols.listitem("--select id--", ""));      }    }   protected void button1_click(object sender, eventargs e)    {      pdfdatasettableadapters.tbl_imgtableadapter td;      td = new pdfdatasettableadapters.tbl_imgtableadapter();      datatable dt = new datatable();      dt = td.getimg(int.parse(dropdownlist1.selectedvalue));      foreach (datarow row in dt.rows)       {          byte[] img2 = (byte[])row["img"];          string base2 = convert.tobase64string(img2);          image1.imageurl = "data:image/jpg;base64," + base2;        }         }  protected void linkbutton1_click(object sender, eventargs e)    {         string sfile = image1.imageurl;         if (string.isnullorempty(sfile))         {             return;         }         fileinfo fi = new fileinfo(server.mappath(sfile)); // error popup here         if (!fi.exists)         {             return;         }         if (!string.isnullorempty(sfile))         {             // check if file image             namevaluecollection imageextensions = new namevaluecollection();             imageextensions.add(".jpg", "image/jpeg");             imageextensions.add(".gif", "image/gif");             imageextensions.add(".png", "image/png");             if (imageextensions.allkeys.contains(fi.extension))             {                 response.contenttype = imageextensions.get(fi.extension);                 response.appendheader("content-disposition", "attachment; filename=" + fi.name);                 response.transmitfile(fi.fullname);                 response.end();             }             response.redirect(sfile);         } 

aspx:

<asp:dropdownlist id="dropdownlist1" runat="server" autopostback="true"> </asp:dropdownlist> <asp:button id="button1" runat="server" onclick="button1_click" text="show" /> <asp:linkbutton id="linkbutton1" runat="server">download</asp:linkbutton> <asp:image id="image1" runat="server" /> 

sql query1:

select id tbl_img 

sql query1:

select img tbl_img (id = @id) 

db:

enter image description here

o/p screen:

enter image description here

when user clicks "download" link, try open image1.url, dataurl, not actual path. causes mappath fail.

the reason why image1.url dataurl set image dataurl when click button 1 (show).

what can parse dataurl file , send that

protected void linkbutton1_click(object sender, eventargs e){     var data = image1.imageurl.split('base64,')[1];     file f = parse.file("filename.jpg", {"base64": data});     response.clear();     response.contenttype = "image/jpg";     response.writefile(f);     response.flush();     response.end(); } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -