📄 admin_file_manager.aspx
字号:
<%@ Page Language="VB" ContentType="text/html" AutoEventWireup="True" validateRequest="false" %>
<%@ Register TagPrefix="admin" TagName="menu" Src="../lib/adminmenu.ascx" %>
<%@ Register TagPrefix="admin" TagName="foot" Src="../lib/adminfoot.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="system.io" %>
<%@ Import Namespace="system" %>
<%@ Import Namespace="system.text" %>
<%@ Import Namespace="Microsoft.VisualBasic" %>
<script runat="server">
dim dir as directoryinfo
dim f as fileinfo
dim strdir as string
sub page_load(obj as object,e as eventargs)
if not page.ispostback then
try
listfiles(tbdir.text)
catch ex as exception
response.Write(ex.message)
end try
end if
end sub
'显示目录
function listfiles(txtdir as string)
tbdir.text=txtdir
viewstate("path")=txtdir
if not directory.exists(tbdir.text) then
response.Write("Invalid directory!")
exit function
end if
dir=new directoryinfo(tbdir.text)
dim hl as hyperlink
dim d as directoryinfo
if dir.root.fullname<>dir.fullname then back.visible="true"
try
datagrid1.datasource=dir.getfiles("*.*")
datagrid1.databind()
datagrid2.datasource=dir.getdirectories
datagrid2.databind()
catch ex as exception
response.Write(ex.message)
end try
end function
'Go back linkbutton on click
sub goback(obj as object,e as eventargs)
try
dir=new directoryinfo(tbdir.text)
listfiles(dir.parent.fullname)
catch ex as exception
response.Write(ex.message)
end try
end sub
'单击VIEW时发生
sub tbdir_handle(obj as object,e as eventargs)
try
listfiles(tbdir.text)
catch ex as exception
response.Write(ex.message)
end try
end sub
'创建目录
sub create_diretory(obj as object,e as eventargs)
Dim path As String = tbdir.text
Try
' Determine whether the directory exists.
If Directory.Exists(path) Then
response.write(path & "目录已存在!")
exit sub
End If
' Try to create the directory.
Dim di As DirectoryInfo = Directory.CreateDirectory(path)
response.write("目录创建成功!" & Directory.GetCreationTime(path))
listfiles(viewstate("path"))
Catch ex As Exception
response.write(ex.message)
End Try
end sub
'删除目录
sub datagrid2_delete_dir(obj as object, e as datagridcommandeventargs)
Dim path As String =datagrid2.datakeys(e.item.itemindex).tostring
Try
If Directory.Exists(path) = False Then
response.Write("目录不存在!")
exit sub
End If
Directory.Delete(path, True)
response.Write(path & "目录删除成功!")
listfiles(viewstate("path"))
catch ex as exception
response.Write(ex.message)
end try
end sub
'删除文件
sub datagrid1_delete_file(obj as object, e as datagridcommandeventargs)
Dim path As String =datagrid1.datakeys(e.item.itemindex).tostring
Try
Kill(path)
response.Write(path & "文件删除成功!")
listfiles(viewstate("path"))
Catch ex As Exception
response.write(ex.message)
End Try
end sub
'创建文件
sub create_file(obj as object,e as eventargs)
try
dim fs as new filestream(tbdir.text,filemode.createnew)
fs.close
response.write(tbdir.text & "文件创建成功!")
listfiles(viewstate("path")) '刷新显示
catch ex as exception
response.Write(ex.message)
end try
end sub
'查询
sub query_file(obj as object,e as eventargs)
dim dir as new directoryinfo(viewstate("path"))
try
datagrid1.datasource=dir.getfiles(tbdir.text)
datagrid1.databind()
datagrid2.datasource=dir.getdirectories
datagrid2.databind()
catch ex as exception
response.Write(ex.message)
end try
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''募薷牡牟
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'修改文件
sub btn_on_view(obj as object,e as eventargs)
try
tbdir.text=datagrid1.datakeys(datagrid1.selectedindex).tostring
dim fs as new filestream(tbdir.text,filemode.open,fileaccess.readwrite)
dim objreader as new streamreader(fs)
body.text=objreader.readtoend
objreader.close
fs.close
panel2.Visible="true"
catch ex as exception
response.Write(ex.message)
end try
end sub
'关闭修改文件
sub btn_off_view(obj as object,e as eventargs)
panel2.Visible="false"
end sub
'更新修改文件
sub btn_change(obj as object,e as eventargs)
try
panel2.Visible="false"
dim objwriter as new streamwriter(tbdir.text,false)
objwriter.write(body.text)
objwriter.close
response.write("FILE:" & tbdir.text & "修改成功!")
listfiles(viewstate("path"))
catch ex as exception
response.Write(ex.message)
end try
end sub
'进入所选目录
sub datagrid2_select(obj as object, e as eventargs)
tbdir.text=datagrid2.datakeys(datagrid2.selectedindex).tostring
listfiles(tbdir.text)
end sub
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件管理</title>
<link href="../site_css.css" rel="stylesheet" type="text/css">
</head>
<body background="../images/bg1.gif">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr align="center">
<td height="8" colspan="3">
</td>
</tr>
<tr>
<td width="150" align="left" valign="top"> <admin:menu runat="server"/> </td>
<td width="1" background="../images/dotlinev.gif"></td>
<td width="554" valign="top">
<font face="Arial, Helvetica, sans-serif, ">please enter file name:</font>
<form runat="server">
<asp:label id="lblmessage" runat="server"/>
<asp:textbox BorderColor="#999999" Height="22" BorderStyle="dotted" Font-Name="arial" Font-Size="12px" CssClass="input" Text="C:\" ID="tbdir" runat="server"/>
<asp:button BorderColor="#999999" BorderStyle="dotted" Font-Name="arial" Font-Size="12px" CssClass="button" ID="view" runat="server" Text="View" OnClick="tbdir_handle" />
<asp:button BorderColor="#999999" CssClass="button" BorderStyle="dotted" Font-Name="arial" Font-Size="12px" ID="diretory" runat="server" Text="Create Diretory" OnClick="create_diretory" />
<asp:button BorderColor="#999999" CssClass="button" BorderStyle="dotted" Font-Name="arial" Font-Size="12px" ID="File" runat="server" Text="Create File" OnClick="create_file" />
<asp:button BorderColor="#999999" CssClass="button" BorderStyle="dotted" Font-Name="arial" Font-Size="12px" ID="query" runat="server" Text="Query File" OnClick="query_file" />
<br>
<asp:linkbutton Text="..{BACK}" ID="back" runat="server" OnClick="goback" Visible="false"/>
<!--募薷牡UI-->
<asp:panel ID="panel2" runat="server" Visible="false">
<asp:textbox Columns="100" ID="body" Rows="10" runat="server" TextMode="MultiLine" Wrap="true"/>
<asp:button BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="dotted" CssClass="ss" Font-Name="arial" ForeColor="#666666" ID="submit" runat="server" Text="Submit" OnClick="btn_change"/>
<asp:button BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="dotted" CssClass="ss" Font-Name="arial" ForeColor="#666666" ID="cancel" runat="server" Text="Cancel" OnClick="btn_off_view"/>
</asp:panel>
<asp:panel id="panel1" runat="server" Font-Name="arial" Font-Size="12px"/>
<font face="Arial, Helvetica, sans-serif, ">directory information:<br>
</font>
<asp:datagrid AlternatingItemStyle-BackColor="#CCCCCC" AutoGenerateColumns="true" BorderColor="#666666" BorderStyle="dashed" BorderWidth="1" CellPadding="2" CellSpacing="2" CssClass="ss" Font-Name="arial" Font-Size="10pt" ForeColor="#666666" HorizontalAlign="Center" ID="datagrid2" runat="server" Width="100%" gridline="Horizontal" OnSelectedIndexChanged="datagrid2_select" OnDeleteCommand="datagrid2_delete_dir" DataKeyField="fullname">
<columns>
<asp:buttoncolumn HeaderText="ENTER" text="Enter" commandname="select"/>
<asp:buttoncolumn HeaderText="DELETE" text="Delete" commandname="delete"/>
</columns>
<selecteditemstyle BackColor="#999999" Font-Bold="true"></selecteditemstyle>
</asp:datagrid>
<p></p>
<font face="Arial, Helvetica, sans-serif, ">file information:<br>
</font> </p>
<asp:datagrid AlternatingItemStyle-BackColor="#CCCCCC" AutoGenerateColumns="true" BorderColor="#666666" BorderStyle="dotted" BorderWidth="1" CellPadding="2" CellSpacing="2" CssClass="ss" Font-Name="arial" Font-Size="10pt" ForeColor="#666666" HorizontalAlign="Center" ID="datagrid1" OnDeleteCommand="datagrid1_delete_file" runat="server" Width="100%" gridline="Horizontal" OnSelectedIndexChanged="btn_on_view" DataKeyField="fullname" >
<columns>
<asp:buttoncolumn HeaderText="DELETE" text="Delete" commandname="delete"/>
<asp:buttoncolumn HeaderText="CHANGE" text="Change" commandname="select"/>
</columns>
</asp:datagrid>
</form>
<br>
</td>
</tr>
<tr>
<td colspan="3" height="1" background="../images/dotlineh.gif"></td>
</tr>
</table>
<admin:foot runat="server"/>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -