Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 15, 2012 09:09 AM by Mikesdotnetting
Member
40 Points
36 Posts
Nov 20, 2011 12:30 AM|LINK
hi guys
i would like to display pictures in a folder. How do i get the number of images in a particular folder than how do i loop through?
this is how far i've gone so far:
@{ var imagePath= ""; imagePath = @"newImages\"; } <!DOCTYPE html> <html> <head> <title>Display Existing Images</title> </head> <body> <h1>Display Existing Images</h1>
<div style="padding:10px;"> @if(imagePath != ""){ <img src="@imagePath" alt="Sample Image" width="300px" /> } </div>
</body> </html>
All-Star
154927 Points
19867 Posts
Moderator
MVP
Nov 20, 2011 07:51 AM|LINK
@{ var imagePath = Server.MapPath("~/newImages"); var files = Directory.GetFiles(imagePath); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title></title> </head> <body> Total images: @files.Count() @foreach(var file in files){ <div style="padding:10px"> <img src="newImages/@Path.GetFileName(file)" alt="Sample Image" /> </div> } </body> </html>
2 Points
1 Post
Jul 15, 2012 09:00 AM|LINK
hi please guide where to write this code in c# as
it gives error or displayed in design window
please
Jul 15, 2012 09:09 AM|LINK
This is not Web Forms code. It is code for Web Pages. Post a question to the Web Forms forum: http://forums.asp.net/18.aspx/1?Web+Forms
Kayd
Member
40 Points
36 Posts
looping through images in a folder
Nov 20, 2011 12:30 AM|LINK
hi guys
i would like to display pictures in a folder. How do i get the number of images in a particular folder than how do i loop through?
this is how far i've gone so far:
@{ var imagePath= "";
imagePath = @"newImages\";
}
<!DOCTYPE html>
<html>
<head>
<title>Display Existing Images</title>
</head>
<body>
<h1>Display Existing Images</h1>
<div style="padding:10px;">
@if(imagePath != ""){
<img src="@imagePath" alt="Sample Image" width="300px" />
}
</div>
</body>
</html>
Mikesdotnett...
All-Star
154927 Points
19867 Posts
Moderator
MVP
Re: looping through images in a folder
Nov 20, 2011 07:51 AM|LINK
@{ var imagePath = Server.MapPath("~/newImages"); var files = Directory.GetFiles(imagePath); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title></title> </head> <body> Total images: @files.Count() @foreach(var file in files){ <div style="padding:10px"> <img src="newImages/@Path.GetFileName(file)" alt="Sample Image" /> </div> } </body> </html>Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Mussawerg
Member
2 Points
1 Post
Re: looping through images in a folder
Jul 15, 2012 09:00 AM|LINK
hi please guide where to write this code in c# as
it gives error or displayed in design window
please
Mikesdotnett...
All-Star
154927 Points
19867 Posts
Moderator
MVP
Re: looping through images in a folder
Jul 15, 2012 09:09 AM|LINK
This is not Web Forms code. It is code for Web Pages. Post a question to the Web Forms forum: http://forums.asp.net/18.aspx/1?Web+Forms
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter