World's most popular travel blog for travel bloggers.

C#, Display Image from Direcory

, , No Comments

For Image Display aspx

<asp:repeater id="RepeaterImages" runat="server">
    <itemtemplate>
        <asp:image id="Image" imageurl="<%# Container.DataItem %>" runat="server">
    </asp:image></itemtemplate>
</asp:repeater>

For Page Load (aspx.cs)

protected void Page_Load(object sender, EventArgs e)
{
    string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Images"));
    List images = new List(filesindirectory.Count());

    foreach (string item in filesindirectory)
    {
        images.Add(String.Format("~/Images/{0}", System.IO.Path.GetFileName(item)));
    }

    RepeaterImages.DataSource = images;
    RepeaterImages.DataBind();
}

0 comments:

Post a Comment

Let us know your responses and feedback