[英]need to view image in image viewer control in ASP.net
i read path of image file from Data Base then ineed to view it in image viewer but when i try to do this the image viewer was empty the path of the image that i stored in DB was that ("E:\\MEdia Viewer Project") i don't know the steps i should do or what i can do ......... 我从数据库读取了图像文件的路径,然后想在图像查看器中查看它,但是当我尝试执行此操作时,图像查看器为空,因此我存储在DB中的图像的路径为(“ E:\\ MEdia Viewer Project” )我不知道我应该采取的步骤或我可以做什么.........
<%@ 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 this code is 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 from [Media] where ID=@id", conn);
cmd.Parameters.AddWithValue("@id", ID);
// rdr = cmd.ExecuteReader();
// print the CustomerID of each record
using (var reader = cmd.ExecuteReader())
{
if (reader.Read()) // you 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";
}
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
I know it's awhile since you posted this but for any others that find this! 我知道距您发布此消息已经有一段时间了,但对于其他找到此消息的人来说!
Use a relative path for your images and then to find them relative to your aspx page you use the Server.MapPath and add the relative path to it. 为图像使用相对路径,然后使用Server.MapPath并找到相对于aspx页面的图像,并向其添加相对路径。
eg if (File.Exists( Server.MapPath ("\\Data\\Competitions\\CurrentSeason\\" + round + "\\Intermediate\\Scores.xml"))) 例如,如果(File.Exists( Server.MapPath (“ \\ Data \\ Competitions \\ CurrentSeason \\” +回合+“ \\ Intermediate \\ Scores.xml”)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.