Solved

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

Posted on 2011-03-01
1
431 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:reach_prgmmer
1 Comment
 
LVL 6

Accepted Solution

by:
AkAlan earned 500 total points
ID: 35010820
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" >
                  </asp:TreeView>
 
 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
            tvDirectoryInfo.Nodes.Add(RootNode)
        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
        Else
            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)
            Loop
            ' 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
                    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
                    DirNode.ChildNodes.Add(treeNode)
                End If
                FileCount = (FileCount + 1)

            Loop
            ' 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
            Else
                parentNode.ChildNodes.Add(DirNode)
                Return parentNode
            End If
        End If
        Return New TreeNode()

    End Function


End Class
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question