• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

How to Get list of web pages in the ASP.Net website?

Is there a way programmatically, I can get all the web pages available in my website like a map and display them in my home page or a seperate web page for this display?
1 Solution
I use a method to display folder contents to my users. You will have to clean it up for your use.

Imports SystemIO

 <asp:TreeView ID="tvDirectoryInfo" ExpandDepth="1" runat="server" >
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Page.IsPostBack = False) Then

            Dim RootDir As DirectoryInfo = New DirectoryInfo("\\arctec-web-svr\IntranetFiles\Operations")
            Dim dS As New DirectoryStructure
            Dim RootNode As TreeNode = dS.OutputDirectory(RootDir, Nothing, Me.Page)
            ' add the output to the tree
        End If
        ' tvDirectoryInfo.ExpandAll()
    End Sub

Here is where the heavy lifting is done **********

Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Web

Public Class DirectoryStructure
    Public Function OutputDirectory(ByVal directory As DirectoryInfo, ByVal parentNode As TreeNode, ByVal callingPage As Page) As TreeNode

        If (directory Is Nothing) Then
            Return Nothing
        End If

        ' create a node for this directory
        'filter for unwanted directories, First directory will always be parent so filter won't stop code
        If Left(directory.Name, 4) = "_vti" Or Right(directory.Name, 5) = "files" Then
            ' do nothing
            Dim DirNode As TreeNode = New TreeNode(directory.Name)

            ' get subdirectories of the current directory
            Dim SubDirectories() As DirectoryInfo = directory.GetDirectories()
            ' output each subdirectory
            Dim intDirectoryCount As Integer = 0

            'Loop through directories, and subdirectories (looping through OutputDirectory)until there are no more subdirectories
            Do While (intDirectoryCount < SubDirectories.Length)
                OutputDirectory(SubDirectories(intDirectoryCount), DirNode, callingPage)
                intDirectoryCount = (intDirectoryCount + 1)
            ' grab and output the current directories files

            Dim Files() As FileInfo = directory.GetFiles()

            Dim FileCount As Integer = 0
            Do While (FileCount < Files.Length)

                Dim strFileName As String = Files(FileCount).Name
                'Filter unwanted file types
                If UCase(Right(strFileName, 4)) = ".PDF" Or UCase(Right(strFileName, 4)) = ".HTM" Or UCase(Right(strFileName, 5)) = ".HTML" Then

                                     Dim treeNode As New TreeNode()
                    'get the path of the files directory
                    Dim strFileDir As Object = Files(FileCount).Directory.ToString

                    'Convert string from unc to url
                    strFileDir = Replace(strFileDir, "\", "/")
                                       strFileDir = Replace(strFileDir, "//arctec-web-svr/IntranetFiles", "/IntranetFiles")

                    strFileDir = strFileDir + "/" + strFileName
                    treeNode.NavigateUrl = strFileDir

                    Dim strTreeNodeName As String = Left(strFileName, (Len(strFileName) - 4)) _
                                                   & " (" & (Files(FileCount).Length / 100) & " kb)" _
                                                   & Format((Files(FileCount).LastWriteTime), "  dd MMM, yy")
                    treeNode.Text = strTreeNodeName
                    If Right(strFileName, 4) <> ".htm" Then
                        treeNode.Target = "_blank"
                    End If
                End If
                FileCount = (FileCount + 1)

            ' if the parent node is null, return this node
            ' otherwise add this node to the parent and return the parent

            If (parentNode Is Nothing) Then
                Return DirNode
                Return parentNode
            End If
        End If
        Return New TreeNode()

    End Function

End Class

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now