![]() |
Web Development »
ASP.NET »
Utilities
Advanced
License: The Code Project Open License (CPOL)
Directory Browsing in ASP.Net 2.0By Rupesh BuradAn article on browsing via directories or HTTP, with ASP.NET using Tree View Control |
C# (C# 1.0, C# 2.0, C# 3.0), .NET (.NET 2.0), ASP.NET, Dev
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
The file uploder is the control which help to select the file but not the path of the file or directory and also we can't make a Active X Control for this so with the help of pop-up we provide the user to select file or directory path in the intranet. This pop-up look same like the directory browing in desktop application.
I read this article http://www.codeproject.com/KB/aspnet/Browsing.aspx which is in ASP.net 1.1. I have changed the folder structure with tree view.
Create a C# web application in asp.net 2.0 and add BrowseDirectory.aspx and add following files into your app_code folder
and create a textbox and button on which webform you want to use it. Add onClientClick
of the button and set OnClientClick="showDirectory();" . Add this script
into yout web form for calling the browsing page.
function showDirectory()
{
document.all.TextBox1.value= window.showModalDialog("browseDirectory.aspx",
'jain',
"dialogHeight: 560px; dialogWidth:360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");
return false;
}
Add Node method in the BrowseDirectory.aspx which add the tree node of the directory and files. FileList Constructor takes path and the filters for the files
FileList objList = new FileList(path, "*.*");
TreeNode node = new TreeNode(path,path);
for(int index = 0 ; index < objList.Directories.Length ; index++)
{
string directory = objList.Directories[index];
TreeNode objChildNode = new TreeNode(directory, path + "\\" + directory + "\\");
objChildNode.PopulateOnDemand = true;
objChildNode.Target = "_blank";
parentNode.ChildNodes.Add(objChildNode);
}
foreach (string file in objList.Files)
{
TreeNode objChildNode = new TreeNode(file, path + "\\" + file);
parentNode.ChildNodes.Add(objChildNode);
}
return node;
For selecting the path of the file or directory use the selection event of the tree view
void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
_browseTextBox.Text = TreeView1.SelectedValue;
}
Expanding is base on the directory selection.
void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
if (e.Node.Value.EndsWith("\\"))
{
AddNodes(e.Node.Value, e.Node);
}
}
Finally when you select the path then go back to the parent page with this path
<script language="javascript">
<!--
function SelectAndClose()
{
txtValue = document.getElementById('_browseTextBox');
window.returnValue = txtValue.value;
window.close();
return false;
}
-->
</script>
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 16 Apr 2008 Editor: |
Copyright 2007 by Rupesh Burad Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |