Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-25
1
Medium Priority
?
103 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
1 Comment
 
LVL 1

Accepted Solution

by:
Prashant Jagdale earned 1500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

885 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