<
head
runat
=
"server"
>
<
title
>title>
head>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
table
>
<
tr
>
<
td
>
<
asp:FileUpload
ID
=
"FileUpload1"
runat
=
"server"
/>
<
asp:RegularExpressionValidator
ID
=
"FileUpLoadValidator"
runat
=
"server"
ControlToValidate
=
"FileUpload1"
ErrorMessage
=
"Upload Jpegs,png and Gifs only."
ValidationExpression
=
"^.*\.(jpg|JPG|gif|GIF|PNG|jpeg|png|JPEG)$"
Display
=
"Dynamic"
>asp:RegularExpressionValidator>
<
asp:Label
ID
=
"lblError"
runat
=
"server"
Visible
=
"false"
/>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Upload"
onclick
=
"Button1_Click"
/>
<
asp:Button
ID
=
"Button2"
runat
=
"server"
onclick
=
"Button2_Click"
Text
=
"Show Album"
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
>asp:Label>
td>
tr>
<
tr
>
<
td
>
<
asp:Repeater
ID
=
"Repeater1"
runat
=
"server"
>
<
ItemTemplate
>
Width
=
"200px"
ImageUrl
=
''
Runat
=
"server"
/>
ItemTemplate>
td>
<
td
>
table>
div>
form>
body>
html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.IO;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
// Loading the images by using Fileupload
protected
void
Button1_Click(
object
sender, EventArgs e)
{
if
(FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath(
"~/Album/"
+ FileUpload1.FileName));
}
else
{
Label1.Text =
" No file received"
;
}
}
//Calling method GetPhotos() and bind to the repeater
protected
void
Button2_Click(
object
sender, EventArgs e)
{
Repeater1.DataSource = GetPhotos();
Repeater1.DataBind();
}
// GetPhotos() method is to be invoked when the button2 is clicked
public
List<
string
> GetPhotos()
{
List<
string
> photos =
new
List<
string
>();
string
photoPath = MapPath(
"~/Album"
);
string
[] files = Directory.GetFiles(photoPath);
foreach
(
string
photo
in
files)
photos.Add(
"~/Album/"
+ Path.GetFileName(photo));
return
photos;
}