如何在项目内的特定文件夹中保存图像以及如何读取以分配到imageurl [英] how to save the image in particular folder inside project and how to read to assign into imageurl

查看:65
本文介绍了如何在项目内的特定文件夹中保存图像以及如何读取以分配到imageurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在使用imageurl显示图像。所以,下面的编码工作和完美显示图像



 受保护 < span class =code-keyword> void  imgfun()
{
使用(SqlConnection connection = new SqlConnection(connString))
{

foreach (ListItem list in chek.Items)
{

string sql = .Empty;
sql = 从imagetb中选择图标,其中code_id = + list.value + 且图标不为空;
connection.Open();
SqlCommand command = new SqlCommand(sql,connection);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
byte [] imgData =( byte [])阅读器[ 图标];
Response.BinaryWrite(imgData);

}
}
}
}



但页面刷新时(点击任何其他内容)事件),它变空了。所以一旦从数据库中写入imgData,我需要保存特定文件夹(我将通过右键单击在解决方案文件中创建文件夹)。这是一次又一次地避免连接数据库和写字节到图像。



如何解决这个问题。需要帮助。

解决方案

你可以做这样的事情

  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 this

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

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


这篇关于如何在项目内的特定文件夹中保存图像以及如何读取以分配到imageurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆