Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to bind the images in gridview from server folder..not save image path r image name in database.. i could saver the image code ex- image1,image2 like that and fetch the image code in database and add imagecode + _0.jpg ex- image1_0.jpg that save in one variable imagename that imagename send to folder n match the imagename in folder image.. fetch the image in folder and display in gridview and put the link button in that image its open new page.. pls help me sir..

What I have tried:

How to bind the images in gridview from server folder..not save image path r image name in database.. i could saver the image code ex- image1,image2 like that and fetch the image code in database and add imagecode + _0.jpg ex- image1_0.jpg that save in one variable imagename that imagename send to folder n match the imagename in folder image.. fetch the image in folder and display in gridview and put the link button in that image its open new page.. pls help me sir..
Posted
Updated 20-Jun-16 4:21am
Comments
deepankarbhatnagar 18-Jun-16 3:15am    
Have you tried so please show your code..

1 solution

Here's a quick example how to upload and display an image from a folder. First you need to create a folder that your application has read/write access permissions to it. Assuming that you have a folder named "ImageStorage" within the root of your application that stores the images.

Then you have this HTML markup:
ASP.NET
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />  
<asp:button id="Button1" runat="server" text="Upload" onclick="Button1_Click" xmlns:asp="#unknown" />  
<br />  
<asp:image id="Image1" runat="server" xmlns:asp="#unknown" />  


Here's the code associated.

C#
protected void Button1_Click(object sender, EventArgs e) {  
             StartUpLoad();  
}  
     
private void StartUpLoad() {  
        //get the file name of the posted image  
        string imgName = FileUpload1.FileName;  
        //sets the image path  
        string imgPath = "ImageStorage/" + imgName;            
       //get the size in bytes that  
  
       int imgSize = FileUpload1.PostedFile.ContentLength;  
      
       //validates the posted file before saving  
        if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") {  
           // 10240 KB means 10MB, You can change the value based on your requirement  
                if (FileUpload1.PostedFile.ContentLength > 10240) {  
                           Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);  
                 }  else {  
                           //then save it to the Folder  
                           FileUpload1.SaveAs(Server.MapPath(imgPath));  
                           Image1.ImageUrl = "~/" + imgPath;  
                           Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);  
                }  
    
          }  
}  
 
Share this answer
 

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