62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="file_manager.aspx.cs" Inherits="WebFile.simple._1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>文件管理</title>
</head>
<body>
<form id="form1" runat="server">
<div>
您当前所在的位置是:<asp:Label ID="lbl_path" runat="server"></asp:Label>
<br />
请输入目标地址:<br />
<asp:TextBox ID="txt_path" runat="server" Width="500px"></asp:TextBox>
<asp:Button ID="btn_to" runat="server" OnClick="btn_to_Click" Text="转到"
Width="84px" />
<br />
转到:<br />
<asp:DropDownList ID="ddl_path" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" OnSelectedIndexChanged="ddl_path_SelectedIndexChanged"
Width="508px">
</asp:DropDownList>
<br />
<asp:Button ID="btn_forward" runat="server" OnClick="btn_forward_Click"
Text="上一层目录" Width="115px" />
<br />
<br />
<asp:GridView ID="gv_File" runat="server" AutoGenerateColumns="False"
DataKeyNames="F_ID,F_name,F_exp" OnRowCommand="gv_File_RowCommand"
OnRowDataBound="gv_File_RowDataBound" OnRowDeleting="gv_File_RowDeleting"
OnSelectedIndexChanging="gv_File_SelectedIndexChanging" CellPadding="4"
ForeColor="#333333" GridLines="None" Height="224px" Width="693px" >
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" Height="35px" />
<Columns>
<asp:BoundField DataField="F_ID" HeaderText="ID" />
<asp:TemplateField HeaderText="名称">
<ItemTemplate>
<asp:HyperLink ID="hlk_name" runat="server" Text='<%# Eval("F_name") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="类型">
<ItemTemplate>
<asp:Label ID="lb_exp" runat="server" Text='<%# Eval("F_exp") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="大小">
<ItemTemplate>
<asp:HyperLink ID="lb_size" runat="server" Text='<%# Eval("F_size") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="最近修改日期">
<ItemTemplate>
<asp:Label ID="lb_time" runat="server" Text='<%# Eval("F_time") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField DeleteText="<div id="de" onclick="JavaScript:return confirm('确定删除吗?')">删除</div>"
ShowDeleteButton="True" />
<asp:ButtonField CommandName="DownLoad" Text="下载" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"
Height="20px" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
file_manager.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebFile.simple
{
public partial class _1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string F_path;
if (!Page.IsPostBack)
{
if (Request.QueryString["F_path"] == null)
{
F_path = Server.MapPath(".");
lbl_path.Text = F_path;
txt_path.Text = F_path;
gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
gv_File.DataBind();
}
else
{
F_path = Server.UrlDecode(Request.QueryString["F_path"]);
lbl_path.Text = F_path;
txt_path.Text = F_path;
gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
gv_File.DataBind();
}
WebDirFile.HardDiskManage.PathBindToDDl(F_path, ref ddl_path);
}
}
protected void gv_File_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DownLoad")
{
string F_path = "";
int index = Convert.ToInt32(e.CommandArgument);
string name = gv_File.DataKeys[index].Values["F_name"].ToString();
string exp = gv_File.DataKeys[index].Values["F_exp"].ToString();
F_path = txt_path.Text;
string FilePath = F_path + "\\" + name;
if (WebDirFile.FileHelper.IsExist(FilePath))
{
//WebDirFile.HardDiskManage.DownLoad(this, FilePath);
WebDirFile.HardDiskManage.download2(this, FilePath);
}
else
{
WebDirFile.MessageBox.Show(this, "目录暂时不能下载哦");
}
}
}
protected void gv_File_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
WebDirFile.MessageBox.Show(this, gv_File.DataKeys[e.RowIndex]["F_name"].ToString());
}
protected void gv_File_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
}
protected void gv_File_RowDataBound(object sender, GridViewRowEventArgs e)
{
//设置连接的地址
if ((HyperLink)e.Row.FindControl("hlk_name") != null)
{
string F_path = "";
HyperLink hlk_name = (HyperLink)e.Row.FindControl("hlk_name");
string exp = gv_File.DataKeys[e.Row.RowIndex].Values["F_exp"].ToString();
string name = gv_File.DataKeys[e.Row.RowIndex].Values["F_name"].ToString();
F_path = txt_path.Text;
string FilePath = F_path + "\\" + name;
string url = "";
if (WebDirFile.FileHelper.IsExist(FilePath))
{
hlk_name.Target = "_blank";
url = WebDirFile.HardDiskManage.ConvertSpecifiedPathToRelativePath(this, FilePath);
}
else
{
url = Request.Url.Segments[Request.Url.Segments.Length - 1].ToString() + "?F_path=" + Server.UrlEncode(F_path + "\\" + name);
}
hlk_name.NavigateUrl = url;
}
}
protected void gv_File_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btn_to_Click(object sender, EventArgs e)
{
string F_path = txt_path.Text;
gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
gv_File.DataBind();
txt_path.Text = F_path;
lbl_path.Text = F_path;
}
protected void btn_forward_Click(object sender, EventArgs e)
{
string RootDir = WebDirFile.DirectoryHelper.GetParentpath(txt_path.Text);
string F_path = RootDir;
txt_path.Text = F_path;
lbl_path.Text = F_path;
if (WebDirFile.DirectoryHelper.IsExist(F_path))
{
gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
gv_File.DataBind();
}
WebDirFile.HardDiskManage.PathBindToDDl(F_path, ref ddl_path);
}
protected void ddl_path_SelectedIndexChanged(object sender, EventArgs e)
{
switch (ddl_path.SelectedItem.Text)
{
case "请选择目标目录":
break;
case "我的电脑":
break;
case "返回上级目录":
string RootDir = WebDirFile.DirectoryHelper.GetParentpath(txt_path.Text);
string F_path = RootDir;
txt_path.Text = F_path;
lbl_path.Text = F_path;
if (WebDirFile.DirectoryHelper.IsExist(F_path))
{
gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
gv_File.DataBind();
}
WebDirFile.HardDiskManage.PathBindToDDl(F_path, ref ddl_path);
break;
default:
F_path = ddl_path.SelectedItem.Text;
txt_path.Text = F_path;
lbl_path.Text = F_path;
gv_File.DataSource = WebDirFile.HardDiskManage.GetFilesTB(F_path);
gv_File.DataBind();
break;
}
}
}
}
PS:我看了书,好像不是我要的内容,头大