Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hello i have table(gridview) i use the features update the upload image i used the

-Gridview Row_updating
-Gridview Row_command
but in the upload column in database i get the name of the file
((* I want the path))



-Gridview Row_updating
C#
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       GridViewRow row = GridView1.Rows[e.RowIndex] as GridViewRow;
       FileUpload FileUpload1 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload1");


       if (FileUpload1 != null && FileUpload1.HasFile)
       {
           FileUpload1.SaveAs(Server.MapPath("~/Cars/Car_Image/" + FileUpload1.FileName));

       }
   }





-Gridview Row_command

What I have tried:

C#
<pre>protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (GridView1.EditIndex == -1) return;
        FileUpload fileUpLoad = GridView1.Rows[GridView1.EditIndex].FindControl("FileUpload1") as FileUpload;
        string fileName = fileUpLoad.FileName;
        TextBox txtImage = GridView1.Rows[GridView1.EditIndex].FindControl("TextBox14") as TextBox;

        if (fileUpLoad != null && fileUpLoad.HasFile)
        {
            txtImage.Text = fileUpLoad.FileName;
        }
        else
        {
            txtImage.Text = txtImage.Text;
        }
    }
Posted
Updated 30-Mar-17 2:48am

1 solution

If you mean the original path of the image on the client then you can't get that for security reasons.
 
Share this answer
 
Comments
Member 13044689 30-Mar-17 8:51am    
then how can i show the image because its not show the image
Member 13044689 30-Mar-17 9:04am    
well why this website is here when u can ask and just the other respond without any help and just 1 line description idk really
F-ES Sitecore 30-Mar-17 9:10am    
If you're storing the image in a folder like /Cars/Car_Image then simply store the filename in the database and when you show the img in an asp:Image control use something like

myImage.ImageUrl = "~/Cars/Car_Image/" + filenameFromDatabase

However what happens when two people upload images with the same filename?
Member 13044689 30-Mar-17 9:20am    
Y but its only 1 Guy use, thx any way

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900