#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    4
    Rep Power
    0

    Repeater - through images


    Hi,

    I do a little bit of web design helping out some mates and I want to loop through some images in a folder but keep getting an error:
    Any help would be greatly recieved.

    here is the repeater code that I am using...

    Code:
    <asp:Repeater runat="server" ID="Repeater1">
            <HeaderTemplate>
                <ul class="gallery">
            </HeaderTemplate>
            <ItemTemplate>
                <li><a rel="gal" href="/images/gallery/<%#((string)Eval("Name")).Replace("-thumb","")%>" onclick="return false;" style='background-image: url(/images/gallery/<%#Eval("Name")%>);'></a></li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>
    here is the .cs code that I am using...

    Code:
    public partial class gallery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    		Master.Page.Title = "Fence staining and painting at Paint Under Pressure";
    		Master.MetaKeywords = "fence, staining, painting, stain, paint, fence staining, fence painting, free quote";
    		Master.MetaDescription = "At Paint Under Pressure we'll take the hassle out of painting or staining your fence.  Contact us for a free quote.";
        
    		if (!IsPostBack)
    		{
    			ListImages();
    		}
    	}
    	
    	private void ListImages()
    	{
    		DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/images/gallery/"));
    		FileInfo[] file = dir.GetFiles();
    		ArrayList list = new ArrayList();
    		foreach (FileInfo info in file)
    		{
    			if (info.Extension == ".jpg" || info.Extension == ".jpeg" || info.Extension == ".gif")
    			{
    				list.Add(info);
    			}
    		}
    	
    		Repeater1.DataSource = list;
    		Repeater1.DataBind();
    	}
    }
    this generates the following error...

    Code:
    Compiler Error Message: CS0246: The type or namespace name 'DirectoryInfo' could not be found (are you missing a using directive or an assembly reference?)
    
    Source Error:
    
    Line 21: 	private void ListImages()
    Line 22: 	{
    Line 23: 		DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/images/gallery/"));
    Line 24: 		FileInfo[] file = dir.GetFiles();
    Line 25: 		ArrayList list = new ArrayList();
    I am guessing that is something to do with the path route but I have tried all combinations and can't seem to get it to work.
    Again any insight would be greatly appreciated...
    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Location
    Ahmedabad
    Posts
    17
    Rep Power
    0
    Hi,

    You can use the below link



    http://www.encodedna.com/aspdotnet/s...-aspdotnet.htm

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo