📄 file_getin.aspx.cs
字号:
break;
case ".gif":
Str_ImgPath = "gif.gif";
break;
case ".jpg":
Str_ImgPath = "jpg.gif";
break;
case ".jpeg":
Str_ImgPath = "jpg.gif";
break;
case ".js":
Str_ImgPath = "script.gif";
break;
case ".txt":
Str_ImgPath = "txt.gif";
break;
case ".xml":
Str_ImgPath = "xml.gif";
break;
case ".zip":
Str_ImgPath = "zip.gif";
break;
case ".rar":
Str_ImgPath = "zip.gif";
break;
default:
Str_ImgPath = "unknown.gif";
break;
}
return Str_ImgPath;
}
/// <summary>
/// 取得当前路径
/// </summary>
string PathPre()
{
string path_ = str_FilePath + Request.Form["Path"];
if (path_ != null)
{
int i, j;
i = path_.LastIndexOf("" + fpath1 + "");
j = path_.Length - i;
path_ = path_.Substring(i, j);
}
else
{
path_ = "" + fpath1 + "";
}
return path_;
}
/// <summary>
/// 修改文件夹名称
/// </summary>
protected void EidtDirName(string path)
{
string Str_OldName = Request.Form["OldFileName"];
string Str_NewName = Request.Form["NewFileName"];
if (Directory.Exists(path + "\\" + Str_OldName))
{
if (Str_OldName == "" || Str_OldName == null || Str_OldName == string.Empty || Str_NewName == "" || Str_NewName == null || Str_NewName == string.Empty)
{
pd.SaveUserAdminLogs(1, 1, UserNum, "文件夹名称修改失败", "参数传递错误.");
PageError("参数传递错误!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
if (Str_OldName == Str_NewName)
{
pd.SaveUserAdminLogs(1, 1, UserNum, "文件夹名称修改失败", "名称相同,更换无效.");
PageError("抱歉,名称相同,更换无效", "File_GetIn.aspx?id=" + FP + "");
}
else
{
Directory.Move(path + "\\" + Str_OldName, path + "\\" + Str_NewName);
pd.SaveUserAdminLogs(1, 1, UserNum, "文件夹名称修改成功", "更改文件夹名成功.");
PageRight("更改文件夹名成功!", "File_GetIn.aspx?id=" + FP + "");
}
}
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "文件夹名称修改失败", "参数传递错误.");
PageError("参数传递错误!", "File_GetIn.aspx?id=" + FP + "");
}
}
/// <summary>
/// 修改文件名称
/// </summary>
protected void EidtFileName(string path)
{
string Str_OldName = Request.Form["OldFileName"];
string Str_NewName = Request.Form["NewFileName"];
if (File.Exists(path + "\\" + Str_OldName))
{
if (Str_OldName == "" || Str_OldName == null || Str_OldName == string.Empty || Str_NewName == "" || Str_NewName == null || Str_NewName == string.Empty)
{
pd.SaveUserAdminLogs(1, 1, UserNum, "文件名称修改失败", "参数传递错误.");
PageError("参数传递错误!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
File.Move(path + "\\" + Str_OldName, path + "\\" + Str_NewName);
pd.SaveUserAdminLogs(1, 1, UserNum, "文件名称修改成功", "修改成功.");
PageRight("更改文件名成功!", "File_GetIn.aspx?id=" + FP + "");
}
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "文件名称修改失败", "参数传递错误.");
PageError("参数传递错误!", "File_GetIn.aspx?id=" + FP + "");
}
}
/// <summary>
/// 删除文件夹
/// </summary>
protected void DelDir(string path)
{
if (Directory.Exists(path)) //判断此文件夹是否存在
{
try
{
Directory.Delete(path, true);
pd.SaveUserAdminLogs(1, 1, UserNum, "删除文件夹", "删除文件夹成功.");
PageRight("删除文件夹成功!", "File_GetIn.aspx?id=" + FP + "");
}
catch (IOException e)
{
PageError(e.ToString(), "");
}
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "删除文件夹失败", "参数错误.");
PageError("参数错误!", "File_GetIn.aspx?id=" + FP + "");
}
}
/// <summary>
/// 删除文件
/// </summary>
protected void DelFile(string path)
{
string Str_FileName = Request.Form["filename"];
if (File.Exists(path + "\\" + Str_FileName)) //判断此文件是否存在
{
FileInfo fso = new FileInfo(path + "\\" + Str_FileName);
try
{
fso.Delete();
}
catch (Exception e)
{
PageError(e.ToString(), "");
}
pd.SaveUserAdminLogs(1, 1, UserNum, "删除文件", "删除文件成功.");
PageRight("删除文件成功!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "删除文件", "参数错误.");
PageError("参数错误!", "File_GetIn.aspx?id=" + FP + "");
}
}
/// <summary>
/// 清空图片
/// </summary>
/// <param name="_Path"></param>
/// <param name="_DateNum"></param>
protected void clearFile(string _Path, string _DateNum)
{
if (!NetCMS.Common.Input.IsInteger(_DateNum))
{
PageError("请输入正整数!", "File_GetIn.aspx?id=" + FP + "");
}
FileInfo[] NewFileInfo; //当前所有文件
DirectoryInfo FatherDirectory = new DirectoryInfo(_Path); //当前目录
NewFileInfo = FatherDirectory.GetFiles(); //得到文件集,可以进行操作
string Str_FileName = "";
foreach (FileInfo DirFile in NewFileInfo)//获取此级目录下的所有文件(文件夹)
{
DateTime d1 = Convert.ToDateTime(System.DateTime.Now);
DateTime d2 = Convert.ToDateTime(DirFile.LastWriteTime);
TimeSpan s = d1 - d2;
double ss = s.TotalDays;
if (ss >= int.Parse(_DateNum))
{
Str_FileName = DirFile.Name.ToString();
if (File.Exists(_Path + "\\" + Str_FileName)) //判断此文件是否存在
{
FileInfo fso = new FileInfo(_Path + "\\" + Str_FileName);
if (DirFile.Extension.ToString() == ".jpg" || DirFile.Extension.ToString() == ".jpeg" || DirFile.Extension.ToString() == ".gif" || DirFile.Extension.ToString() == ".ico" || DirFile.Extension.ToString() == ".png" || DirFile.Extension.ToString() == ".bmp" || DirFile.Extension.ToString() == ".swf")
{
fso.Delete();
}
}
}
}
PageRight("" + _DateNum + " 天前的图片文件清空成功!", "File_GetIn.aspx?id=" + FP + "");
}
/// <summary>
/// 添加文件夹
/// </summary>
protected void AddDir(string path)
{
string Str_DirName = Request.Form["filename"];
if (Directory.Exists(path + "\\" + Str_DirName) == false) //判断此文件夹是否已存在
{
try
{
Directory.CreateDirectory(path + "\\" + Str_DirName.Replace(".", ""));
}
catch (Exception e)
{
PageError(e.ToString(), "");
}
pd.SaveUserAdminLogs(1, 1, UserNum, "添加文件夹", "添加文件夹成功.");
PageRight("添加文件夹成功!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "添加文件夹失败", "此文件夹已存在.");
PageError("此文件夹已存在!", "File_GetIn.aspx?id=" + FP + "");
}
}
/// <summary>
/// 移动文件夹
/// </summary>
/// Code By ChenZhaoHui
protected void MoveFileFolder(string path)
{
string Str_OldName = Request.Form["OldFileName"];
string Str_NewName = Request.Form["NewFileName"];
if (Directory.Exists(path + "\\" + Str_NewName + "\\" + Str_OldName) == false) //判断在目的文件夹中是否已存在该要转移的源文件夹,若不存在,则继续下一步
{
if (Str_OldName == "" || Str_OldName == null || Str_OldName == string.Empty || Str_NewName == "" || Str_NewName == null || Str_NewName == string.Empty)
{
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "警告!参数传递错误.");
PageError("警告!参数传递错误!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
if (Directory.Exists(path + "\\" + Str_NewName + "\\") == false)//判断路径是否正确
{
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "警告!路径错误.");
PageError("路径错误!" + "<br>" + "请您确保您的文件夹路径正确!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
Directory.Move(path + "\\" + Str_OldName, path + "\\" + Str_NewName + "\\" + Str_OldName);//开始转移文件夹
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "恭喜!转移文件夹成功.");
PageRight("恭喜!转移文件夹成功!", "File_GetIn.aspx?id=" + FP + "");
}
}
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "此文件夹已存在,不能转移");
PageError("此文件夹已存在,不能转移!" + "<br>" + "或请您选择其他的文件夹进行转移!", "File_GetIn.aspx?id=" + FP + "");
}
}
/// <summary>
/// 移动文件
/// </summary>
/// Code By ChenZhaoHui
protected void MoveFile(string path)
{
string Str_OldName = Request.Form["OldFileName"];
string Str_NewName = Request.Form["NewFileName"];
if (File.Exists(path + "\\" + Str_NewName + "\\" + Str_OldName) == false) //判断在目的文件夹中是否已存在该要转移的源文件,若不存在,则继续下一步
{
if (Str_OldName == "" || Str_OldName == null || Str_OldName == string.Empty || Str_NewName == "" || Str_NewName == null || Str_NewName == string.Empty)
{
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "警告!参数传递错误");
PageError("警告!参数传递错误!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
if (Directory.Exists(path + "\\" + Str_NewName + "\\") == false)//判断路径是否正确
{
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "警告!路径错误");
PageError("路径错误!" + "<br>" + "请您确保您的文件夹路径正确!", "File_GetIn.aspx?id=" + FP + "");
}
else
{
File.Move(path + "\\" + Str_OldName, path + "\\" + Str_NewName + "\\" + Str_OldName);//开始转移文件
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "恭喜!转移文件成功");
PageRight("恭喜!转移文件成功!", "File_GetIn.aspx?id=" + FP + "");
}
}
}
else
{
pd.SaveUserAdminLogs(1, 1, UserNum, "移动文件夹", "此文件已在目的文件夹中存在,不能转移");
PageError("此文件已在目的文件夹中存在,不能转移!" + "<br>" + "或请您选择其他的文件夹进行转移!", "");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -