protected void btnExit_Click1(object sender, ImageClickEventArgs e) { try { int fileId = Convert.ToInt32(Request.QueryString["fileId"]); MyOffice.Models.FileInfo file = FileInfoManager.GetFileByFileId(fileId); if (Directory.Exists(this.lblFilePath.Text)) { Directory.Delete(this.lblFilePath.Text, true); } IList <int> childFileLists = new List <int>(); FileInfoManager.GetAllChildByFileId(childFileLists, Convert.ToInt32(Request.QueryString["fileId"])); foreach (int delfileId in childFileLists) { FileInfoManager.DelFileById(delfileId); } FileInfoManager.DelFileById(Convert.ToInt32(Request.QueryString["fileId"])); Response.Redirect("FileMain.aspx?fileId=" + file.ParentId + "&fileTypeId=1"); } catch (Exception ex) { throw; } }
protected void gvFileDelete_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "revert") { int fileId = Convert.ToInt32(e.CommandArgument); FileInfoManager.revert_IfDelete_ByFileId(fileId); this.gvFileDelete.DataBind(); } else if (e.CommandName == "del") { try { int fileId = Convert.ToInt32(e.CommandArgument); FileInfo file = FileInfoManager.GetFileByFileId(fileId); //从本地删除文件(夹) if (file.FileType.FileTypeId == 1) { System.IO.Directory.Delete(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + file.FilePath, true); } else { System.IO.File.Delete(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + file.FilePath); } //将要删除的子(子)文件集合 如果被删除的是文件 delLists.count为0 IList <int> delLists = new List <int>(); FileInfoManager.GetAllChildByFileId(delLists, fileId); //先删除本文件(夹) FileInfoManager.DelFileById(fileId); //如果是文件夹则要删除其下所有文件(夹) foreach (int delFileId in delLists) { FileInfoManager.DelFileById(delFileId); } this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功!');location='RecycleBin.aspx'</script>"); } catch { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败!');location='RecycleBin.aspx'</script>"); } } }
//移动 protected void btnMove_Click(object sender, EventArgs e) { try { //被移动的文件夹 MyOffice.Models.FileInfo move_File = FileInfoManager.GetFileByFileId(Convert.ToInt32(ViewState["Move_FileId"])); if (!ViewState["Move_FileId"].ToString().Equals(ViewState["moveTo_FileId"].ToString())) { IList <int> childFileLists = new List <int>(); FileInfoManager.GetAllChildByFileId(childFileLists, move_File.FileId); if (!childFileLists.Contains(Convert.ToInt32(ViewState["moveTo_FileId"]))) { //移动到的文件夹 MyOffice.Models.FileInfo moveTo_File = FileInfoManager.GetFileByFileId(Convert.ToInt32(ViewState["moveTo_FileId"])); //移动磁盘中的文件或文件夹 if (move_File.FileType.FileTypeId == 1) { MoveFolder(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + move_File.FilePath, IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + moveTo_File.FilePath); } else { MoveFile(IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + move_File.FilePath, IniFile.IniReadValue(((MyOffice.Models.User)Session["Login"]).UserId) + moveTo_File.FilePath); } //判断是否是根目录 string fileName = move_File.FilePath.Substring(move_File.FilePath.LastIndexOf("\\") + 1); if (moveTo_File == null) { move_File.ParentId = 0; move_File.FilePath = fileName; } else { move_File.ParentId = moveTo_File.FileId; move_File.FilePath = moveTo_File.FilePath + "\\" + fileName; } //移动文件 即修改文件的父ID 和FilePath FileInfoManager.MoveFile(move_File); ViewState["Move_FileId"] = null; ViewState["moveTo_FileId"] = null; this.txtMove.Text = ""; this.txtMoveFileName.Text = ""; this.btnMove.Enabled = false; this.gvFile.DataBind(); this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动成功!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>"); } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动失败:目标文件是源文件夹的子文件夹!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>"); } } else { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动失败:目标文件和源文件夹相同!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>"); } } catch (Exception ex) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('移动失败!');location='FileMain.aspx?fileId=" + Request.QueryString["fileId"] + "'</script>"); } }