Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello,

i am showing image using imageurl. so, The below coding works and show images perfectly

C#
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.
Posted
Updated 19-Mar-14 3:34am
v3

1 solution

you can do something like this
ASM
byte[] imgData = (byte[])reader["icon"];

File.WriteAllBytes("your apps local folder path", imgData );
 
Share this answer
 
v2
Comments
christhuxavier 20-Mar-14 8:26am    
hi Naz, your code worked for me thanks a lot.

byte[] imgData = (byte[])reader["icon"];

File.WriteAllBytes("your apps local folder path", buffer);

but small correction i made in your coding. i used imgData instead of buffer ..
Naz_Firdouse 20-Mar-14 9:14am    
yes... that's correct...I forgot to change the obj name there
thanks for pointing it out
Naz_Firdouse 20-Mar-14 9:14am    
updated the answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900