You must Sign In to post a response.
  • Category: ASP.NET

    How to fetch the image from the folder

    i have one folder called digital in that lot of images are there.

    My design as follows

    Desitnation CHN - TBM(in label)

    in that digital folder CHN - TBM.png image is there.

    i want to check CHN - TBM label is match with the digital folder CHN - TBM.png i want to display that image in page load

    for that how can i do in asp.net using C#.
  • #767395
    Hi,

    If you want to get back stored image file from your physical location then refer below sample code this might be helpful to you.


    protected void Bind_GV()
    {
    cmd = new SqlCommand("Get_Employees", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@DeptNo", DeptNo);
    dt = new DataTable();

    try
    {
    con.Open();
    da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
    GV.DataSource = dt;
    GV.DataBind();
    }
    else
    {
    DataRow dr = dt.NewRow();

    dt.Rows.Add(dr);
    dt.AcceptChanges();
    GV.DataSource = dt;
    GV.DataBind();
    GV.Rows[0].Visible = false;
    }
    if (num == 0)
    {
    int n = dt.Rows.Count;
    for (int i = 0; i < n; i++)
    {
    //fetch image from DataBase
    string file = dt.Rows[i][7].ToString();
    //give specific path of the image
    string path = "Image/" + file;
    //find image control from Gridview
    Image img = (Image)GV.Rows[i].FindControl("img");
    // assign path to image
    img.ImageUrl = path;
    }
    num = 1;
    }
    }
    catch (Exception ex)
    {

    }
    finally
    {
    con.Close();
    con.Dispose();
    }
    }


    if you want more details then refer below link, http://www.dotnetspider.com/resources/45091-Insert-Edit-Update-Delete-Get-back-Image-from-DataBase.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments