Thursday, July 10, 2014

Get all folder name within a folder and bind into a repeater

Sometimes its necessary to get the all folder name within a folder or directory. So in this tutorial I will show you how to get all the folder name and put those into an array and then bind the array to a repeater.

So first get the all folder name.

Add a new namespace into the cs file.

using System.IO;

The code is

DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/FolderName"));
DirectoryInfo[] name = dir.GetDirectories();

Now put this name array in a repeater

Repeater1.DataSource = name;
Repeater1.DataBind();

And in the repeater add the code to display the folder name.


<!--Add your style sheet-->
<asp:Repeater ID="Repeater1" runat="server">
  <ItemTemplate>
      <%# Container.DataItem %>
      <br />
  </ItemTemplate>
</asp:Repeater>

Now on a button click add these two codes to generate directory details within a directory.

Download the full source code here.

0 comments:

Post a Comment

Follow by Email

Popular Posts

Pageviews