Skip Navigation LinksHome > Browse by Catagory > Input N Output > Display Images in a Folder


Displaying images in specified folder

Quick n easy way to display images in folders
below is how to display all image files in specified folder using datalist.

1. Design
<asp:DataList ID="dtlImg1" runat="server">
    <ItemTemplate>
      <asp:Image ID="imgThum1" runat="server" Width="90" ImageUrl='<%#FormatURL(DataBinder.Eval(Container.DataItem, "Name"))%>' />
      <asp:Label ID="lblFileName" runat="server" Text='<%#Eval("Name") %>'/>
    </ItemTemplate>
</asp:DataList>


2. Behind the code
Don't forget to import Imports System.IO
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    'Set directory where you want to browse
    Dim strRootPath As String = "/users/mypic/"
    Dim myDirInfo As DirectoryInfo

    myDirInfo = New DirectoryInfo(Server.MapPath(strRootPath))

    dtlImg1.DataSource = myDirInfo.GetFiles()
    dtlImg1.DataBind()
End Sub
Tag: Images Folder IO
By: syantien | 1/13/2008 6:04:41 AM / 1/13/2008 6:08:36 AM

Comment

vnb

From: bbb
gbgg
Updated: 9/3/2010 6:07:46 AM

From: bbb
gbgg
Updated: 9/3/2010 6:07:38 AM

samanta

From: samanta
bSZQeN http://djb3jDdmjckow30cnjcmd61l0dy.com
Updated: 8/31/2010 11:03:18 AM

I have problem with this

From: sajid
It shows the error like format URL does not exist
Updated: 6/19/2010 6:48:16 AM

lidia

From: lidia
4GfYcH http://www.f8dpybvfNnMed027gchhA94jc.net
Updated: 5/29/2010 7:52:57 AM

asp.net

From: srinu
I want to display all images from a particular folder on a web page, such that web page shows thumbnails of images and after clicking on thumbnail, image should get open in new window. Plz send me the code in asp.net
Updated: 4/19/2010 10:15:23 AM

Re:Displaying images in specified folder

From: Guest:kasim
It shows the error like format URL is not declared..
Updated: 9/2/2009 12:39:16 PM

Re:Displaying images in specified folder

From: Guest:rrhandle
Code does not work. No images, just boxes with red "X"s
Updated: 6/22/2009 10:55:02 PM



Comment

Name
 

Title

Email

Comment
 

Your IP Address is: 38.107.191.82

* to keep comments safe and clean, we display and keep your ip address.