Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to show hard disk tree view in asp.net application of client machi

Status
Not open for further replies.

sykbhowal

Programmer
Apr 20, 2012
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Configuration;
using System.Data;
using System.IO;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Media;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace treeview_asp
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


/* getDrives();
if (cDrives.Items.Count != 0)
cDrives.Text = cDrives.Items[0].ToString();*/


if (Page.IsPostBack == false)
{
// System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo(Server.MapPath("~/"));
// System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo("C:\\Users\\SAYAK");
System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo("K:\\SilverlightApplication1");
//System.IO.DriveInfo abcd = new System.IO.DriveInfo("k");
// string[] name = Directory.GetDirectories("C:\\Users\\SAYAK\\Desktop");
// System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo(name[0]);


// output the directory into a node
TreeNode RootNode = OutputDirectory(RootDir, null);
// TreeNode RootNode = OutputDrive(abcd, 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;
}

/*private void getDrives()
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady) //Check to see there is something in the drive
// cDrives.Items.Add(drive.RootDirectory);
DropDownList1.Items.Add("C:\\");
}
}*/


}

}

Is there other process to show the total hard disk tree view in web application?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top