0
我從數據庫中獲取二進制字節,並將它們轉換爲PNG圖像,並將它們保存在項目的/ Images文件夾中,並通過標籤顯示它們。這些文件是在Developer環境中創建和使用的,但是一旦我發佈它,文件就會在images文件夾中創建,但它不會被讀取或顯示在IMG標籤中。圖像顯示在開發版本,但沒有顯示後發佈項目asp.net
public string Image_Binary(string pic_id)
{
var imagepath=ConfigurationManager.AppSettings["ImagePath"];
string picstring;
string pid = pic_id;
string path = imagepath+ pid + ".Png";
if (pid != null && pid != "")
{
if (File.Exists(Server.MapPath(path)))
{
picstring = imagepath + pid + ".Png";
}
else
{
DataSet picds = DB.fetchdata("select PictureBinary FROM Picture where Id=" + pic_id);
byte[] picbin = (byte[])picds.Tables[0].Rows[0][0];
ImageConverter ic = new ImageConverter();
System.Drawing.Image img = (System.Drawing.Image)ic.ConvertFrom(picbin);
img.Save(Server.MapPath(imagepath + pid + ".Png"), System.Drawing.Imaging.ImageFormat.Png);
picstring = imagepath + pid + ".Png";
}
}
else
{
//picstring = null;
picstring = "#";
}
return picstring;
}
的Web.config進入
<appSettings>
<add key="ImagePath" value="~/ProductImages/"
</appSettings>
右鍵點擊你的頁面,點擊檢查元素並查看文件路徑,你也應該在404錯誤控制檯 – saj