📄 file_getin.aspx.cs
字号:
//======================================================
//== (c)2008 aspxcms inc by NeTCMS v1.0 ==
//== Forum:bbs.aspxcms.com ==
//== Website:www.aspxcms.com ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;
using NetCMS.Content.Common;
using System.IO;
public partial class Manage_File_GetIn : NetCMS.Web.UI.ManagePage
{
public Manage_File_GetIn()
{
Authority_Code = "Q020";
}
Sys rd = new Sys();
rootPublic pd = new rootPublic();
#region
string FP = NetCMS.Config.UIConfig.filePass();//从Web.config中读取文件密码信息
public string str_dirMana = NetCMS.Config.UIConfig.dirDumm;//获取用户虚拟路径
#endregion
#region 从配置文件读出文件管理路径
public string fpath1 = NetCMS.Config.UIConfig.filePath.Split(',')[0];//userfiles目录
string str_FilePath = "";
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (str_dirMana != "" && str_dirMana != null && str_dirMana != string.Empty)
str_dirMana = "//" + str_dirMana;
string FileID = Request.QueryString["Id"];
Response.CacheControl = "no-cache"; //清除缓存
#region 判断进入文件管理权限并输入密码正确才可以进入
if (FileID != "" && FileID != null)
{
if (FP != FileID)
{
pd.SaveUserAdminLogs(1, 1, UserNum, "文件管理登陆失败", "登陆密码错误.");
PageError("密码错误,请重新输入!", "File_Win_Login.aspx");
}
}
else
{
pd.SaveUserAdminLogs(0, 1, UserNum, "文件管理登陆成功", "文件管理登陆成功.");
Response.Redirect("File_Win_Login.aspx");
}
#endregion
if (!IsPostBack) //判断页面是否重载
{
copyright.InnerHtml = CopyRight; //获取版权信息
}
if (SiteID == "0")
{
str_FilePath = Server.MapPath(str_dirMana + "\\" + fpath1);
}
else
{
string _sitePath = str_dirMana + "\\" + NetCMS.Config.UIConfig.dirSite + "\\" + SiteID;
if (!Directory.Exists(Server.MapPath(_sitePath))) { Directory.CreateDirectory(Server.MapPath(_sitePath)); }
str_FilePath = Server.MapPath(_sitePath);
}
string type = Request.Form["Type"];
string Path = str_FilePath + Request.Form["Path"];
string ParentPath = str_FilePath + Request.Form["ParentPath"]; //父级
try
{
if (Path.IndexOf(str_FilePath, 0) == -1 || ParentPath.IndexOf(str_FilePath, 0) == -1)
Response.End();
}
catch { }
#region 传递参数
switch (type)
{
case "EidtDirName": //修改文件夹名称
EidtDirName(Path);
break;
case "EidtFileName": //修改文件名称
EidtFileName(Path);
break;
case "DelDir": //删除文件夹
DelDir(Path);
break;
case "DelFile": //删除文件
DelFile(Path);
break;
case "AddDir":
AddDir(Path); //添加文件夹
break;
case "MoveFileFolder": //移动文件夹
MoveFileFolder(Path);
break;
case "MoveFile": //移动文件
MoveFile(Path);
break;
case "clearFile":
string _DateNum = Request.Form["dateNums"];
clearFile(Path, _DateNum);
break;
default:
break;
}
#endregion
ShowFile(str_FilePath, Path, ParentPath);
}
/// <summary>
/// 显示文件
/// </summary>
/// <param name="defaultpath"></param>
/// <param name="path"></param>
/// <param name="parentPath"></param>
protected void ShowFile(string defaultpath, string path, string parentPath)
{
try
{
if (path != "" && path != null && path != string.Empty)
{
defaultpath = path;
}
if (Directory.Exists(defaultpath) == false) //判断文件管理目录是否存在
{
PageError("目录不存在", "");
}
filemanage_list.InnerHtml = FileManageList(defaultpath, parentPath);
}
catch { }
}
/// <summary>
/// 文件管理页
/// </summary>
/// <param name="dir"></param>
/// <param name="ParPath"></param>
/// <returns></returns>
protected string FileManageList(string dir, string ParPath)
{
DirectoryInfo[] ChildDirectory; //子目录集
FileInfo[] NewFileInfo; //当前所有文件
DirectoryInfo FatherDirectory = new DirectoryInfo(dir); //当前目录
ChildDirectory = FatherDirectory.GetDirectories("*.*"); //得到子目录集
NewFileInfo = FatherDirectory.GetFiles(); //得到文件集,可以进行操作
#region 获取目录以及文件列表
string Str_TempFileStr;
string Str_TrStart = "<tr class=\"TR_BG_list\">";
string Str_TrEnd = "</tr>";
string Str_TdStart = "<td class=\"list_link\" align=\"left\">";
string Str_TdEnd = "</td>";
string Str_TempParentstr;
string TempParentPath = dir.Replace("\\", "\\\\"); //路径转移
string Str_help = "<span class=\"helpstyle\" style=\"cursor:help;\" title=\"点击查看帮助\" onClick=\"Help('H_FileManage_0001',this)\">帮助</span>";//帮助提示
string Str_help1 = "<span class=\"helpstyle\" style=\"cursor:help;\" title=\"点击查看帮助\" onClick=\"Help('H_FileManage_0002',this)\">帮助</span>";//帮助提示
#endregion
#region 取得当前所在目录
if (ParPath == "" || ParPath == null || ParPath == string.Empty || ParPath == "undefined")
{
Str_TempParentstr = "当前目录:" + dir + Str_help;
}
else
{
string _str_TempletTF = "";
if (SiteID == "0")
{
_str_TempletTF = str_dirMana + "\\" + fpath1;
}
else
{
_str_TempletTF = str_dirMana + "\\" + NetCMS.Config.UIConfig.dirSite + "\\" + SiteID + "\\" + fpath1;
}
if (dir == Server.MapPath(_str_TempletTF)) //判断是否是文件根目录,如果是则不显示返回上级目录
{
Str_TempParentstr = "当前目录:\\" + fpath1 + dir.Replace(str_FilePath, "");
}
else
{
ParPath = ParPath.Replace("\\", "\\\\");
string Str_strpath = TempParentPath.Remove(TempParentPath.LastIndexOf("\\") - 1).Replace(str_FilePath.Replace("\\", "\\\\"), "");//获取当前目录的上级目录
Str_TempParentstr = "<a href=\"javascript:ListGo('" + Str_strpath.Replace(str_FilePath.Replace("\\", "\\\\"), "") + "','" + TempParentPath.Replace(str_FilePath, "") + "');\" class=\"list_link\" title=\"点击回到上级目录\">返回上级目录</a> | 当前目录:\\" + fpath1 + dir.Replace(str_FilePath, "");
}
}
OperateFile(TempParentPath.Replace(str_FilePath.Replace("\\", "\\\\"), "")); //调用显示创建目录,上传文件,移动,删除 函数
#endregion
#region 文件及文件夹列表页显示
Str_TempFileStr = "<table border=\"0\" class=\"table\" width=\"98%\" cellpadding=\"5\" cellspacing=\"1\">";
Str_TempFileStr = Str_TempFileStr + "<td class=\"list_link\" align=\"left\"colspan=\"5\">" + Str_TempParentstr + Str_TdEnd + Str_TrEnd;
Str_TempFileStr = Str_TempFileStr + Str_TrStart;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "名称" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "类型" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "大小(byte)" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "最后修改时间" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "操作" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TrEnd;
#endregion
#region 获取文件夹的目录信息
TempParentPath = TempParentPath.Replace(str_FilePath.Replace("\\", "\\\\"), "");
foreach (DirectoryInfo dirInfo in ChildDirectory) //获取此级目录下的一级目录(文件夹)
{
Str_TempFileStr = Str_TempFileStr + Str_TrStart;
string TempPath = dirInfo.FullName.Replace("\\", "\\\\");
TempPath = TempPath.Replace(str_FilePath.Replace("\\", "\\\\"), "");
Str_TempFileStr = Str_TempFileStr + "<td class=\"list_link\" align=\"left\"><img src=\"../../sysImages/FileIcon/folder.gif\" alt=\"点击进入下级目录\"><a href=\"javascript:ListGo('" + TempPath + "','" + TempParentPath + "');\" class=\"list_link\" title=\"点击进入下级目录\">" + dirInfo.Name.ToString() + "</a></td>";
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "文件夹</td>";
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "-" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "<span style=\"font-size:10px\">" + dirInfo.LastWriteTime.ToString() + "</span>" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "<a href=\"javascript:EditFolder('" + TempParentPath + "','" + dirInfo.Name + "')\" class=\"list_link\" title=\"点击为此文件夹更名\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/editname.gif\" border=\"0\" alt=\"为此项改名\" /></a><a href=\"javascript:MoveFileFolder('" + TempParentPath + "','" + dirInfo.Name + "')\" class=\"list_link\" title=\"移动此文件夹\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/remove1.gif\" border=\"0\" alt=\"转移此项\" /></a><a href=\"javascript:DelDir('" + TempPath + "')\" class=\"list_link\" title=\"点击删除此文件夹\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/del.gif\" border=\"0\" alt=\"删除此项\" />" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TrEnd;
}
#endregion
#region 获取文件夹下文件的信息
foreach (FileInfo DirFile in NewFileInfo)//获取此级目录下的所有文件(文件夹)
{
Str_TempFileStr = Str_TempFileStr + Str_TrStart;
Str_TempFileStr = Str_TempFileStr + "<td class=\"list_link\" align=\"left\"><img src=\"../../sysImages/FileIcon/" + GetFileIco(DirFile.Extension.ToString()) + "\">" + DirFile.Name.ToString() + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + DirFile.Extension.ToString() + "文件" + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + DirFile.Length.ToString() + Str_TdEnd;
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "<span style=\"font-size:10px\">" + DirFile.LastWriteTime.ToString() + "</span>" + Str_TdEnd;
if ((DirFile.Extension.ToString() == ".asa" || DirFile.Extension.ToString() == ".css" || DirFile.Extension.ToString() == ".shtml" || DirFile.Extension.ToString() == ".shtm" || DirFile.Extension.ToString() == ".html" || DirFile.Extension.ToString() == ".htm" || DirFile.Extension.ToString() == ".asp" || DirFile.Extension.ToString() == ".aspx" || DirFile.Extension.ToString() == ".txt" || DirFile.Extension.ToString() == ".java" || DirFile.Extension.ToString() == ".cs" || DirFile.Extension.ToString() == ".xml" || DirFile.Extension.ToString() == ".asax"))
{
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "<a href=\"File_OnLine_Edit.aspx?dir=" + TempParentPath + "&filename=" + DirFile.Name + "\" class=\"list_link\" title=\"在线编辑\"><img src=\"../../sysImages/folder/Vedit.gif\" border=\"0\" alt=\"在线编辑\" /></a><a href=\"File_Txt_Edit.aspx?dir=" + TempParentPath + "&filename=" + DirFile.Name + "\" class=\"list_link\" title=\"文本编辑\"><img src=\"../../sysImages/folder/Tedit.gif\" border=\"0\" alt=\"文本编辑\" /></a><a href=\"javascript:MoveFile('" + TempParentPath + "','" + DirFile.Name + "')\" class=\"list_link\" title=\"移动此文件\"><img src=\"../../sysImages/folder/js.gif\" border=\"0\" alt=\"转移此项\" /></a><a href='http://" + Request.ServerVariables["Server_Name"] + str_dirMana + "\\" + PathPre() + "\\" + DirFile.Name + "' class=\"list_link\" title=\"点击预览此文件\" target=\"_blank\"><img src=\"../../sysImages/folder/review.gif\" border=\"0\" alt=\"预览该文件\" /></a><a href=\"javascript:EditFile('" + TempParentPath + "','" + DirFile.Name + "')\" class=\"list_link\" title=\"点击为此文件更名\"><img src=\"../../sysImages/folder/re.gif\" border=\"0\" alt=\"为此项改名\" /></a><a href=\"javascript:DelFile('" + TempParentPath + "','" + DirFile.Name + "')\" class=\"list_link\" title=\"点击删除此文件\"><img src=\"../../sysImages/folder/del.gif\" border=\"0\" alt=\"删除此项\" /></a>" + Str_TdEnd;
}
else
{
Str_TempFileStr = Str_TempFileStr + Str_TdStart + "<a href=\"javascript:MoveFile('" + TempParentPath + "','" + DirFile.Name + "')\" class=\"list_link\" title=\"移动此文件\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/remove1.gif\" border=\"0\" alt=\"转移此项\" /></a><a href='http://" + Request.ServerVariables["Server_Name"] + str_dirMana + "\\" + PathPre() + "\\" + DirFile.Name + "' class=\"list_link\" title=\"点击预览此文件\" target=\"_blank\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/review.gif\" border=\"0\" alt=\"预览该文件\" /></a><a href=\"javascript:EditFile('" + TempParentPath + "','" + DirFile.Name + "')\" class=\"list_link\" title=\"点击为此文件更名\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/editname.gif\" border=\"0\" alt=\"为此项改名\" /></a><a href=\"javascript:DelFile('" + TempParentPath + "','" + DirFile.Name + "')\" class=\"list_link\" title=\"点击删除此文件\"><img src=\"../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/sysico/del.gif\" border=\"0\" alt=\"删除此项\" /></a>" + Str_help1 + Str_TdEnd;
}
Str_TempFileStr = Str_TempFileStr + Str_TrEnd;
}
Str_TempFileStr = Str_TempFileStr + "</table>";
return Str_TempFileStr;
#endregion
}
/// <summary>
/// 显示功能导航菜单
/// </summary>
protected void OperateFile(string path)
{
string Str_Addfiledir = "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" class=\"Navitable\" align=\"center\">";
Str_Addfiledir = Str_Addfiledir + "<tr>";
Str_Addfiledir = Str_Addfiledir + "<td style=\"padding-left:14px;\"><a href=\"File_GetIn.aspx?id=" +NetCMS.Common.Input.URLEncode(Request.QueryString["id"]) + "\" class=\"menulist\">管理首页</a> ┊ <a href=\"javascript:AddDir('" + path + "');\" class=\"menulist\">创建目录</a> ┊ <a href=\"javascript:UpFile('" + path + "');\" class=\"menulist\">上传文件</a> ┊ (<a href=\"javascript:getDateNum_del('" + path + "');\" class=\"menulist\"> 清空图片文件</a>,选择几天前的图片:<input type=\"Text\" name=\"dateNum\" value=\"\" class=\"form\" style=\"width:30px;\">)";
Str_Addfiledir = Str_Addfiledir + "</td>";
Str_Addfiledir = Str_Addfiledir + "</tr>";
Str_Addfiledir = Str_Addfiledir + "</table>";
operatefile.InnerHtml = Str_Addfiledir;
}
/// <summary>
/// 获取文件图标
/// </summary>
protected string GetFileIco(string type)
{
string Str_ImgPath;
switch (type.ToLower())
{
case ".htm":
Str_ImgPath = "html.gif";
break;
case ".html":
Str_ImgPath = "html.gif";
break;
case ".shtm":
Str_ImgPath = "html.gif";
break;
case ".shtml":
Str_ImgPath = "html.gif";
break;
case ".aspx":
Str_ImgPath = "aspx.gif";
break;
case ".cs":
Str_ImgPath = "c.gif";
break;
case ".asp":
Str_ImgPath = "asp.gif";
break;
case ".doc":
Str_ImgPath = "doc.gif";
break;
case ".exe":
Str_ImgPath = "exe.gif";
break;
case ".swf":
Str_ImgPath = "flash.gif";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -