更新时间:2023-08-26 20:27:28
你可以做这样的事情byte [] imgData =(byte [])阅读器[ icon] ;
File.WriteAllBytes( 您的应用本地文件夹路径,imgData); 跨度>
hello,
i am showing image using imageurl. so, The below coding works and show images perfectly
protected void imgfun()
{
using (SqlConnection connection = new SqlConnection(connString))
{
foreach (ListItem list in chek.Items)
{
string sql = string.Empty;
sql = "Select icon from imagetb where code_id =" + list.value+ " and icon is not null";
connection.Open();
SqlCommand command = new SqlCommand(sql, connection);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
byte[] imgData = (byte[])reader["icon"];
Response.BinaryWrite(imgData);
}
}
}
}
but when the page gets refresh(by clicking any other event), it gets empty. so once writted imgData from the database , i need to save in particular folder(i will create folder in solution file by right clicking) inside. which is avoiding again and again connecting database and writing byte to image everytime.
how to solve this. help needed.
you can do something like thisbyte[] imgData = (byte[])reader["icon"]; File.WriteAllBytes("your apps local folder path", imgData );