请教各位天才: 如何在asp.net(c#)环境下实现浏览文件夹的功能??? 非常感谢您的关照!!!
解决方案 »
- string str = null 与 string str = “” 有什么区别啊
- 300分求救.NET网站布署后无法读取数据的问题。急!!!
- A页面执行完某代码后,在B页面执行某代码
- 如何从sqlserver中取出图片显示,谢谢了.在线等
- 奇怪的现象,关于关闭窗口的问题?
- 关于二级域名请教,如何在用户注册后根据用户名自动开通二级域名?
- 修改密码
- 请教一下关于ajax安全性的问题..
- 想在静态页面中记录点击次数
- 各位大侠:客户端问题!求助!!
- 新手请问如何用程序使窗口自动刷新一次?请大家多多帮忙!在线急等
- webdiyer的分页控件:用多重select语句然后自定义了一个参数问题,程序报错 “必须声明变量 '@categorycode'”的问题!!
如果想要图形化界面的得按需要加载DirectoryDialog或FileDialog控件.试试吧.
谢谢
怎么没人来帮呢?
谢谢前几位的指点 可能我没说清楚
还有没有高招了?
TNND,微软公司也不想个办法搞一个出来.
-----------------
实在不行,自行写个ActiveX吧。
<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>
<script runat="server"> // Insert page code here
//
void Page_Load(object sender,EventArgs e)
{ if(!IsPostBack)
{
string DiskPath = Server.MapPath(".");
lblRootPath.Text = Server.MapPath(".");
BindDiskInfo(DiskPath);
}
}
void BindDiskInfo(string DiskPath)
{
DirectoryInfo di = new DirectoryInfo(DiskPath); DataGrid1.DataSource = di.GetDirectories();
DataGrid1.DataBind(); DataGrid2.DataSource = di.GetFiles();
DataGrid2.DataBind(); ViewState["ParentPath"] = di.Parent.FullName;
ViewState["CurrentPath"] = DiskPath;
//ViewState["ParentPath"] = Server.MapPath(".."); } void Button1_Click(object sender, EventArgs e) {
DirectoryInfo di = new DirectoryInfo(ViewState["CurrentPath"].ToString());
string SubDirName = tbxDirectoryName.Text.Trim();
di.CreateSubdirectory(SubDirName); DataGrid1.DataSource = di.GetDirectories();
DataGrid1.DataBind();
} void DataGrid1_SelectedIndexChanged(object sender, EventArgs e) { } void DataGrid1_EditCommand(object sender, DataGridCommandEventArgs e) {
string DiskPath = e.Item.Cells[0].Text.Trim();
BindDiskInfo(DiskPath);
} void Button2_Click(object sender, EventArgs e) {
if(lblRootPath.Text.Length > ViewState["ParentPath"].ToString().Length)
{
return;
}
BindDiskInfo(ViewState["ParentPath"].ToString());
} void Button3_Click(object sender, EventArgs e) {
string ClientFileName = upFile.Value;
string[] TempArr = ClientFileName.Split("\\".ToCharArray());
string ClientFileExtendName = TempArr[TempArr.Length - 1]; string SaveFileName = ClientFileExtendName;
upFile.PostedFile.SaveAs(Server.MapPath(SaveFileName)); BindDiskInfo(ViewState["CurrentPath"].ToString());
}</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here --><asp:Label id="lblRootPath" runat="server" forecolor="#cceeaa" font-size="Larger" backcolor="Blue"></asp:Label>
<table style="BORDER-RIGHT: blue 1px solid; BORDER-TOP: blue 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: blue 1px solid; BORDER-BOTTOM: blue 1px solid" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="320">
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="DataGrid1_SelectedIndexChanged" OnEditCommand="DataGrid1_EditCommand">
<Columns>
<asp:BoundColumn DataField="FullName" HeaderText="文件夹"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" CancelText="取消" EditText="进入"></asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
<br />
<div style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid">
<asp:TextBox id="tbxDirectoryName" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="NewDir"></asp:Button>
<asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="ToParent"></asp:Button>
<br />
<input id="upFile" type="file" runat="server" />
<asp:Button id="Button3" onclick="Button3_Click" runat="server" Text="Save"></asp:Button>
</div>
</td>
<td width="2" bgcolor="#aaccee">
</td>
<td>
<asp:DataGrid id="DataGrid2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="文件名"></asp:BoundColumn>
<asp:BoundColumn DataField="Length" HeaderText="大小"></asp:BoundColumn>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="最后更新时间"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<a target="_blank" href='<%#DataBinder.Eval(Container.DataItem,"Name")%>'>浏览</a>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>
<script runat="server"> // Insert page code here
//
void Page_Load(object sender,EventArgs e)
{ if(!IsPostBack)
{
string DiskPath = Server.MapPath(".");
lblRootPath.Text = Server.MapPath(".");
BindDiskInfo(DiskPath);
}
}
void BindDiskInfo(string DiskPath)
{
DirectoryInfo di = new DirectoryInfo(DiskPath); DataGrid1.DataSource = di.GetDirectories();
DataGrid1.DataBind(); DataGrid2.DataSource = di.GetFiles();
DataGrid2.DataBind(); ViewState["ParentPath"] = di.Parent.FullName;
ViewState["CurrentPath"] = DiskPath;
//ViewState["ParentPath"] = Server.MapPath(".."); } void Button1_Click(object sender, EventArgs e) {
DirectoryInfo di = new DirectoryInfo(ViewState["CurrentPath"].ToString());
string SubDirName = tbxDirectoryName.Text.Trim();
di.CreateSubdirectory(SubDirName); DataGrid1.DataSource = di.GetDirectories();
DataGrid1.DataBind();
} void DataGrid1_SelectedIndexChanged(object sender, EventArgs e) { } void DataGrid1_EditCommand(object sender, DataGridCommandEventArgs e) {
string DiskPath = e.Item.Cells[0].Text.Trim();
BindDiskInfo(DiskPath);
} void Button2_Click(object sender, EventArgs e) {
if(lblRootPath.Text.Length > ViewState["ParentPath"].ToString().Length)
{
return;
}
BindDiskInfo(ViewState["ParentPath"].ToString());
} void Button3_Click(object sender, EventArgs e) {
string ClientFileName = upFile.Value;
string[] TempArr = ClientFileName.Split("\\".ToCharArray());
string ClientFileExtendName = TempArr[TempArr.Length - 1]; string SaveFileName = ClientFileExtendName;
upFile.PostedFile.SaveAs(Server.MapPath(SaveFileName)); BindDiskInfo(ViewState["CurrentPath"].ToString());
}</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here --><asp:Label id="lblRootPath" runat="server" forecolor="#cceeaa" font-size="Larger" backcolor="Blue"></asp:Label>
<table style="BORDER-RIGHT: blue 1px solid; BORDER-TOP: blue 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: blue 1px solid; BORDER-BOTTOM: blue 1px solid" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="320">
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="DataGrid1_SelectedIndexChanged" OnEditCommand="DataGrid1_EditCommand">
<Columns>
<asp:BoundColumn DataField="FullName" HeaderText="文件夹"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" CancelText="取消" EditText="进入"></asp:EditCommandColumn>
</Columns>
</asp:DataGrid>
<br />
<div style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid">
<asp:TextBox id="tbxDirectoryName" runat="server"></asp:TextBox>
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="NewDir"></asp:Button>
<asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="ToParent"></asp:Button>
<br />
<input id="upFile" type="file" runat="server" />
<asp:Button id="Button3" onclick="Button3_Click" runat="server" Text="Save"></asp:Button>
</div>
</td>
<td width="2" bgcolor="#aaccee">
</td>
<td>
<asp:DataGrid id="DataGrid2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="文件名"></asp:BoundColumn>
<asp:BoundColumn DataField="Length" HeaderText="大小"></asp:BoundColumn>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="最后更新时间"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<a target="_blank" href='<%#DataBinder.Eval(Container.DataItem,"Name")%>'>浏览</a>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
非常感谢!!
[email protected]
http://www.cnblogs.com/wssmax/archive/2005/06/03/167329.html
这个浏览本机
http://www.cnblogs.com/wssmax/archive/2005/06/03/167342.html