从数据库取出上传的图片,把该图片保存到服务器磁盘上,如何实现?
在我的一个aspx.cs上需要从数据库里取出很多图片,我需要把这些图片存到服务器磁盘上,然后将服务器上图片的路径返回回来,作为另外一张网页上img的 src的参数.
我已经能从数据库中得到
图片的编号(ImageID)和内容(ImageContent)了,我需要把这个ImageContent存到服务器上,并且将这个图片命名为ImageID.ico.
我这样写的,但是不正确
private void CreatIcon(DataTable dv)
{
string ImageID="wr";
string filePath=Http://" + HttpContext.Current.Request.Url.Host +HttpContext.Current.Request.ApplicationPath+"/images" ;
try
{
foreach (DataRow dr in dv.Rows)
{
ImageID = dr["ImageID"].ToString();
byte[] buffer = (byte[])dr["ImageContent"];
filePath = filePath+ @"\"+ImageID+".ico";
FileStream fout = new FileStream(pp,FileMode.OpenOrCreate);
BinaryWriter bw = new BinaryWriter(fout);
bw.Write(buffer);
bw.Close();
fout.Close();
bw = null;
fout = null;
}
}