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;

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

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

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

Download the full source code here.


Post a Comment

Follow by Email

Popular Posts