c# - need to view image in image viewer control in ASP.net -
i read path of image file data base ineed view in image viewer when try image viewer empty path of image stored in db ("e:\media viewer project") don't know steps should or can .........
<%@ page language="c#" autoeventwireup="true" codefile="images.aspx.cs" inherits="images" %> <!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> <style type="text/css"> .style6 { text-align: left; height: 61px; } .style7 { height: 274px; text-align: left; } .style8 { text-align: center; height: 42px; font-family: "arial black"; color: #000099; } .style9 { height: 274px; text-align: left; width: 121px; } </style> </head> <body> <form id="form2" runat="server"> <table style="width: 100%; margin-left: 17px;"> <tr> <td align="center" bgcolor="#cc6699" class="style6" colspan="2"> <br /> <asp:sitemappath id="sitemappath1" runat="server" font-names="verdana" font-size="0.8em" pathseparator=" : "> <currentnodestyle forecolor="#333333" /> <nodestyle font-bold="true" forecolor="#7c6f57" /> <pathseparatorstyle font-bold="true" forecolor="#5d7b9d" /> <rootnodestyle font-bold="true" forecolor="#5d7b9d" /> </asp:sitemappath> </td> </tr> <tr> <td bgcolor="#990099" class="style9"> </td> <td bgcolor="white" class="style7" valign="top"> title: <asp:textbox id="titletextbox" runat="server"></asp:textbox> <br /> file path :<asp:textbox id="pathtextbox" runat="server"></asp:textbox> <br /> upload date <asp:textbox id="datetextbox" runat="server"></asp:textbox> <br /> <asp:image id="image1" runat="server" height="282px" width="393px" /> <br /> <br /> <br /> <br /> </td> </tr> <tr> <td bgcolor="#990099" class="style8" colspan="2" valign="middle"> </td> </tr> </table> <div> </div> </form> </body> </html>
and code in load page
public partial class images : system.web.ui.page { protected void page_load(object sender, eventargs e) { sqldatareader rdr=null; sqlconnection conn=null; try { string id = request.querystring["id"]; conn = new sqlconnection("data source=shimofcis-pc\\mysql;initial catalog=mydb;integrated security=sspi"); sqlcommand cmd; conn.open(); cmd = new sqlcommand("select title,filepath,uploaddate [media] id=@id", conn); cmd.parameters.addwithvalue("@id", id); // rdr = cmd.executereader(); // print customerid of each record using (var reader = cmd.executereader()) { if (reader.read()) // don't need while loop { pathtextbox.text = reader["filepath"].tostring(); datetextbox.text = reader["uploaddate"].tostring(); titletextbox.text = reader["title"].tostring(); image1.imageurl = pathtextbox.text + "\"+titletextbox.text+ "+".jpg"; } } } { // close reader if (rdr != null) { rdr.close(); } // 5. close connection if (conn != null) { conn.close(); } } } }
i know it's awhile since posted others find this!
use relative path images , find them relative aspx page use server.mappath , add relative path it.
e.g. if (file.exists(server.mappath("\data\competitions\currentseason\" + round + "\intermediate\scores.xml")))
Comments
Post a Comment