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

    I tried but image path is not coming correctly

    i am fetching the image from the folder

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


    Desintation CHN - TBM (Label Name)

    in that digital folder CHN - TBM image is there. i want to check the image name and label name should be same. then display image


    My code as follows

    protected void Page_Load(object sender, EventArgs e)
    {
    string imgname = lbltext.Text.ToString();
    string folderPath = Server.MapPath("digital/" + imgname);
    if (folderPath == imgname.ToString())
    {
    lblresult.Text = folderPath;
    }
    }

    But in folder path i get as follows when i check using break point

    D:\Dot Net Practical Excercise\WebApplication1\WebApplication1\digital\CHN - TBM

    from the above i want to get only CHN - TBM


    in my above code what is the mistake i made.
  • #767398
    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/

  • #767402
    Hi,
    If you want only 'CHN - TBM' from 'D:\Dot Net Practical Excercise\WebApplication1\WebApplication1\digital\CHN - TBM', refer this:

    string folderPath=Server.MapPath("digital/" + imgname);
    folderPath = folderPath.Substring(folderPath.LastIndexOf("\\"));


  • Sign In to post your comments