DavidJGu's Blog
尼采说,宁可追求虚无也不能无所追求!
Keeping is harder than winning
posts - 42, comments - 18, trackbacks - 1, articles - 13
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
一种站点aspx文件浏览器设计
Posted on 2004-09-17 19:54
Let's DotNet
阅读(835)
评论(2)
编辑
收藏
所属分类:
tech
我们在调试aspx文件时,经常有时想转到自己想要的一个页面看看,此时若Session过期重新登陆时要重输url或者要在菜单里寻找。往往我们只关系某几个模块。文件浏览或许可以发挥一些作用。
Steve Sharrock
在
http://aspalliance.com/
发表了[
TreeView - Programming an Explorer-style Site View
]一文(
http://aspalliance.com/125
),但正如user comments所言,所提出的方法在实现上有一定的缺陷。本文基于Infragistics的NetAdvantage(4.2)控件提出一种设计方法。该方法可直接推广到Microsoft的TreeView控件上。算法比较简单,直接给出代码示例。
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
Infragistics.WebUI.Shared;
namespace
Company.FolderBrowser.TreeView
{
/**/
///
<summary>
///
Summary description for DocTree.
///
aspx文件浏览器
///
</summary>
public
class
DocTree : System.Web.UI.Page
{
private
const
string
imgurl
=
"
./Image/
"
;
private
int
iDomainLen;
protected
Infragistics.WebUI.UltraWebNavigator.UltraWebTree UltraWebTree1;
string
strDomain;
public
DocTree()
{
Page.Init
+=
new
System.EventHandler(Page_Init);
}
private
void
Page_Load(
object
sender, System.EventArgs e)
{
if
(
!
this
.IsPostBack )
{
//
生成根节点
Infragistics.WebUI.UltraWebNavigator.Node objNode;
objNode
=
new
Infragistics.WebUI.UltraWebNavigator.Node();
objNode.ImageUrl
=
imgurl
+
"
folder.gif
"
;
objNode.Text
=
"
Root
"
;
objNode.Tag
=
"
folder
"
;
UltraWebTree1.Nodes.Add(objNode);
//
递归获取目录和文件
GetFolders(MapPath(
"
~/./
"
),UltraWebTree1.Nodes[
0
].Nodes );
UltraWebTree1.Expandable
=
true
;
}
}
private
void
Page_Init(
object
sender, EventArgs e)
{
InitializeComponent();
//
iDomainLen = Server.MapPath("").Length;
//
因为当前文件在2级目录,所以域长度获取去上一级目录长度
//
相应地,取域名时也要截掉当前目录
iDomainLen
=
Server.MapPath(
"
../
"
).Length;
string
strURL
=
Request.Url.ToString();
try
{
strURL
=
strURL.Substring(
0
,strURL.LastIndexOf(
'
/
'
));
}
catch
{
strURL
=
Request.Url.ToString();
}
int
iFootindex
=
strURL.LastIndexOf(
'
/
'
);
if
(iFootindex
>
0
)
{
strDomain
=
strURL.Substring(
0
,iFootindex)
+
"
/
"
;
}
else
{
strDomain
=
strURL;
}
}
/**/
///
<summary>
///
递归获取文件夹和相关文件,并填充到节点
///
</summary>
///
<param name="path">
目录路径
</param>
///
<param name="nodes">
填充节点
</param>
private
void
GetFolders(
string
path, Infragistics.WebUI.UltraWebNavigator.Nodes nodes)
{
//
获取子目录
string
[] dirs
=
Directory.GetDirectories( path );
foreach
(
string
p
in
dirs )
{
string
dp
=
p.Substring(path.Length);
if
( dp.StartsWith(
"
_v
"
) )
continue
;
//
排除以_v开头的frontpage文件夹
nodes.Add(Node(
""
,p.Substring(path.Length),
"
folder
"
) );
}
//
获取目录内文件,过滤非aspx文件
string
[] files
=
Directory.GetFiles(path,
"
*.aspx
"
);
foreach
(
string
p
in
files )
{
nodes.Add( Node( p, p.Substring(path.Length ),
"
file
"
) );
}
//
增加子文件夹及其文件(递归)
for
(
int
i
=
0
; i
<
nodes.Count; i
++
)
{
if
( nodes[i].Tag.ToString()
==
"
folder
"
)
{
GetFolders(dirs[i]
+
"
\
"
, nodes[i].Nodes );
}
}
}
/**/
///
<summary>
///
创建节点
///
</summary>
///
<param name="path">
路径
</param>
///
<param name="text">
显示文本
</param>
///
<param name="type">
标记类型
</param>
///
<returns>
节点
</returns>
private
Infragistics.WebUI.UltraWebNavigator.Node Node(
string
path,
string
text,
string
type )
{
Infragistics.WebUI.UltraWebNavigator.Node n
=
new
Infragistics.WebUI.UltraWebNavigator.Node();
n.Tag
=
type;
n.Text
=
text;
n.ImageUrl
=
imgurl
+
"
folder.gif
"
;
n.SelectedImageUrl
=
imgurl
+
"
folderopen.gif
"
;
if
( type
==
"
file
"
)
{
string
nav
=
strDomain
+
path.Substring(iDomainLen);
nav.Replace(
'
\
'
,
'
/
'
);
n.TargetUrl
=
nav;
n.ImageUrl
=
imgurl
+
"
file.gif
"
;
n.SelectedImageUrl
=
imgurl
+
"
file.gif
"
;
n.TargetFrame
=
"
doc
"
;
}
return
n;
}
Web Form Designer generated code
#region
Web Form Designer generated code
/**/
///
<summary>
///
Required method for Designer support - do not modify
///
the contents of this method with the code editor.
///
</summary>
private
void
InitializeComponent()
{
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
}
}
调用时,在项目中增加一个文件夹“FolderBrowser”,加入本文件和图片文件夹,将本文件设为主页即可!
Feedback
#1楼
回复
引用
2006-04-12 11:29 by
godspeed [未注册用户]
if ( nodes[i].Tag.ToString() == "folder" )
行 117: {
行 118: GetFolders(dirs[i] + "\\", nodes[i].Nodes );
行 119: }
请问前辈:我试了后总要在这出错(索引超出了数组界限。)
#2楼
回复
引用
2006-05-18 19:26 by
davidjgu [未注册用户]
你的文件目录结构是怎么样的?调用方法是如何写的?可以列出来看一下
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2004-12-05 20:00 编辑过
相关文章:
.NET设计模式系列文章
终于干掉了默认的输入法, 关于ctfmon.exe文件
EventDeliveryFailedException异常
俱乐部活动延期通知
大家别忘了参加27号下午的活动哦
相关链接:
所属分类的其他文章:
Office 2007安装后Google拼音输入法莫名其妙消失了,换成了微软拼音
在装有SAP客户端后安装VS2003时出错
Difference between ICallbackEventHandler and AJAX
无法通过Project Professional 2003连接到Project Server 2003的解决办法(转)
AutoCoder——全新自动代码框架
基于性能的编程技巧点滴
"Union" in Oracle
Atlas Project (转)
DB2编程技巧
动态添加控件的一个注意点
最新IT新闻:
2008年10月11日科技博客精选
搞死开心网还是搞活他?
网络书店“新”军
百度C2C电子商务平台“有啊”youa.com上线
Silverlight 2.0正式版下周发布
Powered by:
博客园
Copyright © Let's DotNet
日历
<
2004年9月
>
日
一
二
三
四
五
六
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
公告
welcom to DavidJGu's Blog
与我互动
给我发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(4)
给我留言
查看私人留言
我参与的团队
苏州.Net俱乐部(0/724)
随笔分类
sentiment(8)
tech(34)
随笔档案
2007年10月 (1)
2007年3月 (1)
2006年9月 (1)
2006年3月 (1)
2006年1月 (1)
2005年10月 (1)
2005年9月 (2)
2005年7月 (1)
2005年6月 (2)
2005年5月 (7)
2005年4月 (2)
2005年1月 (1)
2004年12月 (2)
2004年11月 (5)
2004年9月 (3)
2004年8月 (6)
文章分类
Jokes(2)
Techs(11)
文章档案
2005年9月 (2)
2005年5月 (2)
2005年4月 (1)
2004年12月 (1)
2004年11月 (5)
2004年10月 (1)
2004年9月 (1)
相册
enjoy GIF
forPostUse
happy Life
收藏夹
System design(1)
TreeView
Classmates
Zhang Baohua
Excellent Webs
Delphi, but not only Delphi
GotDotNet
The Microsoft .NET Framework Community
Favorite Blogs
Bruce's Home
daviXiong
donews blog
enhydraboy(database)
First we try, then we trust
Flying---My dream!
jgtm2000[mvp]
Jibbering
Jibbering.com contains the various bits of me, Jim Ley, that I expose to the web, if you're just looking to email me, Jim@jibbering.com is what you need.
joycode
kenly_zhang(oracle)
koffer
myblogjava
navy_koo
sam1111
Scott Watermasysk
Code, Community, Thoughts, and Other Stuff
sunmast's blog
孟子E章
Security Issue
基于角色的安全认证
Tips
导出excel的几种方法
最新评论