Solved

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

Posted on 2014-09-25
1
95 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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