希望对大家有用。

提供事例代码下载,代码中还包含了一个我常用的日至类。
http://files.cnblogs.com/Leodr/FileManagerDemo.rar
在web.config里配置,文件的限制信息
BrowseFiles.aspx:

<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="BrowseFiles.aspx.cs" enableEventValidation="false"
Inherits="CommonPage_FileManager_BrowseFiles" %>
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>
<link href="../FileManager/StyleBrowseFile.css" rel="stylesheet" type="text/css" />
<script language="javascript">

function CreateDir()
{
dirName = prompt('输入要创建的目录名称:','新文件夹');
if ((dirName) && (dirName!=""))
{
document.forms['BrowseFiles'].elements['funcParam'].value = dirName;
__doPostBack('CreateDir', '');
}
}
function Download(path)
{
document.forms['BrowseFiles'].elements['funcParam'].value = path;
__doPostBack('Download', '');
}
function Delete()
{
return confirm('确认要删除所选的文件/文件夹吗?')
// __doPostBack('Delete','');
}
function Rename(path)
{
newName = prompt('输入文件夹/文件的新名称:','');
if ((newName) && (newName!=""))
{
document.forms['BrowseFiles'].elements['funcParam'].value = path;
document.forms['BrowseFiles'].elements['funcExtraParam'].value = newName;
__doPostBack('Rename', '');
}
}
script>
head>
<body>
<form id="BrowseFiles" method="post" runat="server" enctype="multipart/form-data">
<input type="hidden" id="funcParam" runat="server" name="funcParam">
<input type="hidden" id="funcExtraParam" runat="server" name="funcExtraParam">
<asp:Table runat="server" CssClass="TableHeader" Width="100%" ID="Table1">
<asp:TableRow>
<asp:TableCell Width="36">
<asp:Image runat="server" Height="25" Width="25" ImageUrl="./Images/OpenFolder.gif"
ID="Image1" NAME="Image1">asp:Image>
asp:TableCell>
<asp:TableCell>
<asp:Label runat="server" ID="FolderDescription">asp:Label>
asp:TableCell>
<asp:TableCell Width="140px">
操作:<a href="javascript.:CreateDir();"><img border="0" src="./Images/NewFolder.gif"
alt="创建一个新目录" height="20" width="20">a>
<asp:LinkButton ID="CreateDir" runat="server" OnClick="CreateDir_Click" />
<%
--<a href="javascript.:Delete();"><img border="0" src="./Images/Delete.gif" Alt="删除选择的文件/文件夹" height="20" width="20">a>
--%>
<asp:ImageButton ImageUrl="./Images/Delete.gif" ToolTip="删除选择的文件/文件夹" Height="20"
Width="20" ID="ImageButton1" runat="server" OnClientClick="Delete();" OnClick="Delete_Click" /><asp:LinkButton
ID="Delete" runat="server" OnClick="Delete_Click" Visible="False" />
<asp:LinkButton ID="Rename" runat="server" OnClick="Rename_Click" Visible="False" />
<asp:LinkButton ID="Download" runat="server" OnClick="Download_Click" Visible="False" />
asp:TableCell>
asp:TableRow>
asp:Table>
<asp:Table ID="FoldersAndFiles" runat="server" CssClass="Grid_General" Width="100%">
<asp:TableRow CssClass="Grid_Header">
<asp:TableCell Width="36px" Font-Bold="True" />
<asp:TableCell Text="名称" Font-Bold="True" />
<asp:TableCell Width="30px" Font-Bold="True" />
<asp:TableCell Width="40px" Font-Bold="True" />
<asp:TableCell Text="大小" Width="80px" Font-Bold="True" HorizontalAlign="Right" />
<asp:TableCell Text="创建时间" Width="140px" Font-Bold="True" />
<asp:TableCell Text="修改时间" Width="140px" Font-Bold="True" />
asp:TableRow>
asp:Table>
<br>
<asp:Table runat="server" ID="Table2">
<asp:TableRow>
<asp:TableCell Width="80px" Font-Bold="True" Text="上传文件:" />
<asp:TableCell>
<input id="UploadedFile" runat="server" class="LongButton" name="UploadedFile" size="35"
type="file">
asp:TableCell>
<asp:TableCell>
<asp:Button ID="Upload" OnClick="Upload_Click" runat="server" CssClass="Button" Text="上 传">
asp:Button>
asp:TableCell>
asp:TableRow>
asp:Table>
<br>
<asp:Label ID="StatusMessage" runat="server" CssClass="StatusMessage" Visible="False"
Width="100%" />
<asp:Label ID="FolderStyle" runat="Server" Text="Grid_Item" Visible="false" />
<asp:Label ID="FileStyle" runat="Server" Text="Grid_AlternatingItem" Visible="false" />
form>
body>
html>
BrowseFiles.aspx.cs
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Collections;
5
using System.Web;
6
using System.Web.Security;
7
using
using System;2
using System.Data;3
using System.Configuration;4
using System.Collections;5
using System.Web;6
using System.Web.Security;7
using