Hi all
try this example to dispaly all images in spacific folder
Suppose we have folder called “Images” in my Website contains Images with Different extensions
Step1 :- Create a new Website and add new folder called “Images” and add some images in that folder
Step2 :- Add new Web Page and Drag from Toolbox DataList control which we will dispaly images from folder in it
<asp:DataList ID="DataList1" runat="server" RepeatColumns="5" CellPadding="5">
<ItemTemplate>
<asp:Image Width="100" ID="Image1" ImageUrl='<%# Bind("Name", "~/images/{0}") %>' runat="server" />
<br />
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/images/{0}") %>' runat="server"/>
</ItemTemplate>
<ItemStyle BorderColor="Silver" BorderStyle="Dotted" BorderWidth="1px" HorizontalAlign="Center"
VerticalAlign="Bottom" />
</asp:DataList>
and in Code behind add this code :-
protected void Page_Load(object sender, EventArgs e)
{
ListImages();
}
private void ListImages()
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/images"));
FileInfo[] file = dir.GetFiles();
ArrayList list = new ArrayList();
foreach (FileInfo file2 in file)
{
if (file2.Extension == ".jpg" || file2.Extension == ".jpeg" || file2.Extension == ".gif")
{
list.Add(file2);
}
}
DataList1.DataSource = list;
DataList1.DataBind();
}
Don’t forget to use namespace “Using System.IO ;”
Hope this helps
Good Luck
thanks very much.
How do I limit to increase image size?
Comment by Li — February 16, 2012 @ 9:10 pm