Solved

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

Posted on 2011-03-01
1
424 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

12 Experts available now in Live!

Get 1:1 Help Now