簡體   English   中英

如何從數據庫中的ASP.NET圖像控件中加載圖像?

[英]How to load image in image control of ASP.NET from database?

我在項目中創建了一個新文件夾,並將圖像保存在該文件夾中。 我還將路徑存儲在數據庫中。

現在,我想在ASP.NET圖像控件中加載圖像,但無法這樣做。

這是用於存儲路徑的代碼。

if (ImgUpload.HasFile)
{
    string fileName = ImgUpload.FileName;
    string filePath = Server.MapPath("~/Images/FacultyPics/");
    int fileLength = ImgUpload.PostedFile.ContentLength;
    string fileextention = Path.GetExtension(fileName);
    fileextention = fileextention.ToLower();
    string link = "~/Images/FacultyPics/" + fileName;   //this link will be stored in database
    if (fileLength < 1048576)
    {
        if (fileextention == ".jpg" || fileextention == ".png" || fileextention == ".gif" || fileextention == ".bmp")
        {
            ImgUpload.SaveAs(filePath + fileName);
            BAL.Pic = link;
        }
        else
        {
            lblMessage.Text = "Only Image files are allowed";
        }
    }
    else
    {
        lblMessage.Text = "Max file size allowed is 1 MB";
    }
}

Img是ASP.NET圖像控件,但未顯示圖像。

Img.ImageUrl = Page.ResolveUrl(dt.Rows[0][7].ToString());

根據應用程序結構(您的應用程序文件夾結構)檢查aspx頁面如何解析路徑

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM