Home > ASP.Net > Get List of All Pages in Application

Get List of All Pages in Application

Hi All,

In most of the ASP.NET projects I have been working on, I have needed a way to easily navigate to any page in the solution. To accomplish this I usually created some kind of User Control with links to all pages. If the project was small I usually entered the links by hand. For bigger projects I have used a Repeater control and filled it with data from the file system.
The method used to get the data from the file system looks more or less like this:

public string[] GetAllPages()
    int applicationFolderNumberOfCharacters = HttpRuntime.AppDomainAppPath.Length;
    List<string> pages = new List<string>();
    string[] files = Directory.GetFiles(
      HttpRuntime.AppDomainAppPath, "*.aspx", SearchOption.AllDirectories);
    return Array.ConvertAll<string, string>(files, delegate(string file)
        return "~/" +
         file.Substring(applicationFolderNumberOfCharacters).Replace(@"\", "/");

On the Page or User Control the Repeater I use looks as follows:

<asp:Repeater ID=”Links” runat=”server”>
      <a runat=”server” href=’<%# Container.DataItem %>‘><%# Container.DataItem%></a><br />

If you put it on the Master Page, you will get access to every page from every page, which is great during development. Just don’t forget to remove it from the production code.

Hope this helps

Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: