I'm attempting to make an easy photo gallery website. Using ASP.Internet and C#. At this time I do not possess a server setup however i am simply using the expansion one which Visual Studio Begins whenever you create a website project and run it.

I've got a folder on my small hard disk that consists of a mystery quantity of images. I wish to write a bit of code which will undergo each image and add these to the default web page. I've attempted this code however it does not work. What am I doing wrong? Must I be utilising a ListView control or perhaps a DataView or something like that like this? Should i give a virtual directory to be able to access the pictures? If that's the case, how do you to that particular about this test server?

ALSO, how do you set the positioning and alignment of those pictures? For instance, wouldso would I allow it to be to ensure that the images have been in a line up and down and dedicated to the web page?

protected void Page_Load(object sender, EventArgs e)

First you have to put the images you need to display underneath the web tree. Let us assume you have carried out that and they're in folder known as Images. After that you can make use of a Repeater control to show them by data-binding it like so:

Something similar to this...

<asp:Repeater ID="RepeaterImages" runat="server">


        <asp:Image ID="Image" runat="server" ImageUrl='<%# Container.DataItem %>' />



After which inside your code behind:

protected void Page_Load(object sender, EventArgs e)

", System.IO.Path.GetFileName(item)))


    RepeaterImages.DataSource = images


This essentially produces a range of images using their full path in the directory. After that it produces a listing of strings which contain the virtual road to the look. After that it binds that List towards the repeater, which shows the items in it's template, that is a picture control which uses the road because the ImageUrl. It's quick'n'dirty, but works and really should be considered a good beginning point.

You are creating an <img> element having a Link to C:UsersJordanDesktopWeb ImagesSomeImage.digital. Clearly, that will not operate in a internet browser.

You need to copy the pictures to some subfolder of the project, and hang the Hyperlink to a family member URL, such as this:

img.ImageUrl = "~/Web Images/" + Path.GetFileName(s)

(Presuming the Web Images folder is really a subfolder from the application root)

As SLaks informs, you must have your images available to the consumer. By via hosting it on the server or hosting it yourself (apparent).