Solved

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

Posted on 2011-03-01
1
422 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now