Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

In my previous post I have demonstrated how to upload an image to a folder and display the image after uploading here. In this post I will extend a little bit of what I have demonstrated on my previous post. Basically I'm going to demonstrate how to display all the uploaded images from the folder in the web page on click of the Button.

Here's the html mark up:

ASPX:

   1:  <asp:FileUpload ID="FileUpload1" runat="server" />
   2:  <asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
   3:  <br />
   4:  <asp:Image ID="Image1" runat="server" />
   5:  <br />
   6:  <asp:Button ID="Button2" runat="server" Text="Load All Uploaded Images" 
   7:          onclick="Button2_Click" />
   8:  <br />
   9:  <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

 

And here's the code snippet below:

CODE BEHIND:

 

   1:           private void LoadUploadedImages() {
   2:              int index =1;
   3:              DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/ImageStorage"));
   4:              foreach (FileInfo fi in di.GetFiles()) {
   5:                  Image img = new Image();
   6:                  img.ID = "img" + index.ToString();
   7:                  img.Width = Unit.Pixel(100);
   8:                  img.Height = Unit.Pixel(100);
   9:                  img.ImageUrl = "~/ImageStorage/" + fi.Name;
  10:                  PlaceHolder1.Controls.Add(img);
  11:   
  12:                  Literal lit = new Literal();
  13:                  lit.Text = "<br/>";
  14:                  PlaceHolder1.Controls.Add(lit);
  15:                  index++;
  16:              }
  17:          }
  18:   
  19:          protected void Button2_Click(object sender, EventArgs e) {
  20:              LoadUploadedImages();
  21:          }

 

 

And here's the output below:

After Uploading:

 

After clicking the "Load All Uploaded Images" button:

 

That's simple! I hope someone find this post useful!

Technorati Tags: ,,
Posted on Thursday, January 20, 2011 11:13 PM ASP.NET , C# | Back to top


Comments on this post: Displaying All Images from the Folder in the Page

# re: Displaying All Images from the Folder in the Page
Requesting Gravatar...
Simple and straight forward. I lilke it!
Left by Richard on Aug 24, 2011 12:06 AM

# re: Displaying All Images from the Folder in the Page
Requesting Gravatar...
hi
how do u make a image slider from this code
Left by stardust on Jan 02, 2012 9:42 PM

# re: Displaying All Images from the Folder in the Page
Requesting Gravatar...
I dont select all images,how i do it?
Left by rrrrrr on Jun 25, 2012 3:40 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net