Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i cant able to display the images in aspx image. please help me.!!
below i have attached my code below.



FRONT END
VB
<form id="form1"  runat="server">
    <div>
    <asp:FileUpload AllowMultiple="true" ID="fileuploadimages" runat="server" />
    <asp:Button runat="server" ID="btnUpload" CssClass="btnStyle" Text="Upload Image"
        OnClick="btnUpload_Click" />
    <asp:Label ID="listofuploadedfiles" runat="server" />
    <div id="dvGallery"  runat="server">

    </div>
    </div>
    </form>


CODE BEHIND
C#
public partial class galle4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateImage();
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fileuploadimages.HasFiles)
        {
            foreach (HttpPostedFile uploadedFile in fileuploadimages.PostedFiles)
            {
                uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/images/"),
                uploadedFile.FileName));
                listofuploadedfiles.Text = string.Format("updated successfully");
            }
            PopulateImage();
        }
    }
    private void PopulateImage()
    {
        DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Images"));
        foreach (var i in dir.GetFiles())
        {
            dvGallery.InnerHtml = "<img src='~/Images + file.Name'/>";
        }
    }
}
Posted
Updated 6-Oct-15 21:24pm
v2
Comments
F-ES Sitecore 1-Oct-15 5:15am    
Please do basic research before asking a question. Google "upload and display image asp.net" and you'll find thousands of examples.
Richard Deeming 1-Oct-15 9:01am    

Refer this link may be this could be helpful to you Displaying multiple dynamic images in a WebForm[^]
 
Share this answer
 
by using this solution, once the the page refressed, the images get deleted

http://www.aspsnippets.com/Articles/HTML5-Show-Display-multiple-image-preview-before-upload-with-FileUpload-control-using-JavaScript-and-jQuery.aspx[^]

by using this solution, i cant able to display the solution.
http://jqueryasp.net/upload-multiple-image-file-progress-bar-asp-net-using-jquery/[^]..

i have a code to upload the images and it save successfully to the folder. bt i dont know how to display that images in aspx page.
 
Share this answer
 
Comments
Richard Deeming 1-Oct-15 9:01am    
This is not a solution.

If you want to update your question, use the "Improve question" button.

DO NOT post the update as a new solution.
front page:

<asp:fileupload allowmultiple="true" id="fileuploadimages" runat="server" xmlns:asp="#unknown" />
   <asp:button runat="server" id="btnUpload" cssclass="btnStyle" text="Upload Image" xmlns:asp="#unknown">
       OnClick="btnUpload_Click" />
   <asp:label id="listofuploadedfiles" runat="server" /></asp:button>



Code Behind: to upload image

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class gallery : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fileuploadimages.HasFiles)
        {
            foreach (HttpPostedFile uploadedFile in fileuploadimages.PostedFiles)
            {

                uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/images/"),
                uploadedFile.FileName));
                listofuploadedfiles.Text = string.Format("updated successfully");


            }
        }
    }
}
 
Share this answer
 
Comments
Richard Deeming 1-Oct-15 9:02am    
This is also not a solution.
[no name] 5-Oct-15 2:37am    
ya this code is only used to upload the images to the folder. i dont knw how to display those images into the webform.

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