Solved

Need a simple vb asp.net example for displaying the contents of a web server directory

Posted on 2014-09-25
1
97 Views
Last Modified: 2014-10-21
I have an web server that is running on a private internal network.  I maintain the web site and would like to add a directory where certain users can ftp pdf documents.   I  am looking for a simple vb asp.net example to build a web page that when opened would dynamically create a sorted list of documents in this directory with hyperlinks to open them.
0
Comment
Question by:IT-Ed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
Prashant Jagdale earned 500 total points
ID: 40345487
Hi,
Please place the tree view control on a webpage and check if the following code works

<asp:TreeView Id="MyTree"
                      PathSeparator = "|"
                      ExpandDepth="0"
                      runat="server" ImageSet="Arrows"
        AutoGenerateDataBindings="False">
            <SelectedNodeStyle Font-Underline="True"
                HorizontalPadding="0px" VerticalPadding="0px" ForeColor="#5555DD"></SelectedNodeStyle>
            <NodeStyle VerticalPadding="0px" Font-Names="Tahoma" Font-Size="10pt"
                HorizontalPadding="5px" ForeColor="#000000" NodeSpacing="0px"></NodeStyle>
            <ParentNodeStyle Font-Bold="False" />
            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD"></HoverNodeStyle>
         </asp:TreeView>

Open in new window


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Media;
using System.Drawing;
using System.Drawing.Imaging;
public partial class CreateFolder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
        if (Page.IsPostBack == false)
        {
             System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo(Server.MapPath("~/"));
             // output the directory into a node
            TreeNode RootNode = OutputDirectory(RootDir, null);
            // add the output to the tree

             MyTree.Nodes.Add(RootNode);
        }
    }
    

    TreeNode OutputDirectory(System.IO.DirectoryInfo directory, TreeNode parentNode)
    {
        // validate param
        if (directory == null) return null; 
        // create a node for this directory
        TreeNode DirNode = new TreeNode(directory.Name);
        // get subdirectories of the current directory
        System.IO.DirectoryInfo[] SubDirectories = directory.GetDirectories();
       // OutputDirectory(SubDirectories[0], "Directories");
        // output each subdirectory
        for (int DirectoryCount = 0; DirectoryCount < SubDirectories.Length; DirectoryCount++)
        {
            OutputDirectory(SubDirectories[DirectoryCount], DirNode);
        }
        // output the current directories file
        System.IO.FileInfo[] Files = directory.GetFiles();
        for (int FileCount = 0; FileCount < Files.Length; FileCount++)
        {
            DirNode.ChildNodes.Add(new TreeNode(Files[FileCount].Name));
        }        // if the parent node is null, return this node
        // otherwise add this node to the parent and return the parent
        if (parentNode == null)
        {
            return DirNode;
        }
        else
        {
            parentNode.ChildNodes.Add(DirNode);
            return parentNode;
        }
    }
  }

Open in new window

0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 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