先看效果
WebFileManager
代码如下
<!--
Author: 张浩华
DateTime: 2012-07-06 03:25
-----------------------------------
管理Web站点下文件的页面程序。
提供上传、重命名、删除、创建文件夹、下载等功能。
-->
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
string Msg = string.Empty;
static string _CURRENT_PATH = "";
protected void Page_Load(object sender, EventArgs e)
{
InitFiles();
switch (Request["action"])
{
case "Root":
Root();
break;
case "Back":
Back();
break;
case "Open":
Open(Request["FileName"]);
break;
case "Delete":
Delete(Request["FileName"]);
break;
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (fuFile.HasFile)
{
string currentPath = GetCurrentPath();
string fileName = fuFile.FileName;
if (rbCover.Checked)
{
}
else if (rbRename.Checked)
{
while (System.IO.File.Exists(currentPath + fileName))
{
fileName = "new_" + fileName;
}
}
fuFile.SaveAs(currentPath + fileName);
}
InitFiles();
}
protected void btnSave_Click(object sender, EventArgs e)
{
string oleFileName = hfOldName.Value;
string newFileName = txtNewName.Text;
if (string.IsNullOrEmpty(newFileName))
{
Msg = "The file name can't for empty !";
return;
}
string currentPath = GetCurrentPath();
string oldPath = currentPath + oleFileName;
string newPath = currentPath + newFileName;
if (IsFile(oldPath))
{
if (System.IO.File.Exists(newPath))
{
Msg = "The file name repeated, please reset.";
return;
}
System.IO.File.Move(oldPath, newPath);
}
else
{
if (string.IsNullOrEmpty(oleFileName))
{
System.IO.Directory.CreateDirectory(newPath);
}
else
{
System.IO.Directory.Move(oldPath, newPath);
}
}
InitFiles();
}
private void Back()
{
string path = GetCurrentPath();
string parent = new System.IO.DirectoryInfo(path).Parent.FullName + "\";
if (parent.IndexOf(Server.MapPath("~/")) >= 0)
{
_CURRENT_PATH = parent;
}
Response.Redirect(Request.Url.AbsolutePath);
}
private void Delete(s
下一篇:MVC与三层架构的异同点
版权所有 2021-2024 石家庄建站平台 冀ICP备2022000585号-2 24小时服务热线:15383239821