shawl.qiu c# .net FileManager class v1.0(文件管理器)

    技术2022-05-11  51

    shawl.qiu c# .net FileManager class v1.0(文件管理器)

    目录: 1. 简介 2. 核心代码 3. 页面代码 shawl.qiu 2007-02-25 http://blog.csdn.net/btbtd 1. 简介 CREATED BY STABX, AT 2007-2-24. shawl.qiu c# .net FileManager class(文件管理器) ---/------------------------------------------------------------- version 1.0 默认用户名: shawl.qiu  默认密码: aaaaaa 下载: http://files.myopera.com/btbtd/csharp/class/sq_csharp_FileManager_class_v1.0.7z 重要提示: 站点 web.config SessionState 应该设置为 SQLServer 模式, 如下面的设置: <configuration>  <!--  <appSettings>   <add key="sqvalue="just a test" />  </appSettings>-->   <!--Response.Write(ConfigurationSettings.AppSettings["sq"]); -->   <system.web>   <httpRuntime maxRequestLength="20480"    useFullyQualifiedRedirectUrl="true"    executionTimeout="90"    />           <!-- <customErrors defaultRedirect="/include/error/generalError.html"   mode="RemoteOnly" >   <error statusCode="404redirect="/include/error/error404.html" />  </customErrors>-->   <globalization    requestEncoding="UTF-8"   responseEncoding="UTF-8"   fileEncoding="UTF-8"   />  <sessionState mode="SQLServer"   cookieless="true"   timeout="20"   sqlConnectionString="data source=127.0.0.1;user id=sqAspDotNetSession;password=AspDotNetSessionPwd"   >  </sessionState>  </system.web>  </configuration> 或者设置为允许 子目录的 web.config 设置, 在子目录放置上述内容的 web.config 原因为: 使用 FileObj.Move() 或 FileInfoObj.MoveTo() 时, 会导致页面重新编译, 从而丢失 Session. 目前我只找到 Session 的 SQLServer 选项才能解决该问题.  功能摘要:  支持 创建 新文件/新目录   支持编辑文本文件   支持上传文件   支持 移动 文件/目录   支持 删除 文件/目录   支持 重命名 文件/目录   支持 下载文件   支持 验证/不验证(该选项主要为整合程序而设置) 使用权限   支持自定义管理目录   支持编辑用户信息(当选择验证选项时) 写本程序的动机:  主要为整合到我的 sqGallery 画廊程序,   我想为我的画廊程序 增加文件编辑功能,   不过一想可能使代码非常混乱,   就打定主意写一个通用性高的文件管理器,   唉, 那知道,  这是一个无底坑, 写了这么一个杂乱无章的文件管理器,   不过功能还是挺齐全的.   后续版本主要为 简化/优化 代码. © 2007-2008, shawl.qiu All rights reserved. author: shawl.qiu e-mail: shawl.qiu@gmail.com blog: http://blog.csdn.net/btbtd 2007-2-25 0:26:15  2. 核心代码 using System; using System.Collections; using System.Data; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; public delegate void GeneralEventDelegate(Object s, EventArgs e); //public delegate void OneArgStringDelegate(String Str); /*-----------------------------------------------------------------------------------*/  * shawl.qiu c# .net FileManager class v1.0 /*-----------------------------------------------------------------------------------*/ //---------------------------------------------------------------------begin class FileManager public class FileManager {  //-----------------------------------begin event  public FileManager()  {  }   ~FileManager()  {  }  //-----------------------------------end event   //-----------------------------------begin public constant  //-----------------------begin about  public const String auSubject = "shawl.qiu c# .net FileManager class";  public const String auVersion = "v1.0";  public const String au = "shawl.qiu";  public const String auEmail = "shawl.qiu@gmail.com";  public const String auBlog = "http://blog.csdn.net/btbtd";  public const String auCreateDate = "2007-2-19";  //-----------------------end about  //-----------------------------------end public constant   //-----------------------------------begin public variable  public bool Debug = false;  public bool Verify = true;   public string ManageRoot = "/test/";  public string ProgramRoot = "/sqFlMng/";   public string LoginSession = "sqFlMngLogin";  public string CheckCodeSession = "sqFlMngCheckCode";  public string FolderListSession = "flMngVsFolderList";  public string FileListSession = "flMngVsFileList";   public string LoginGotoUrl = "?";  public string LogoutGotoUrl = "?";   public string EditableExtension = ".txt|.asp|.aspx|.ascx|.html|.htm|.xml|.xsl|.xslt|.xsd|"+   ".dtd|s.css|.vbs|.js|.svg|.c|.rss|.wml|.w3d";   public string UploadExtension = "7z,rar,zip,mp3,bmp,gif,jpg,jpeg,png,txt,swf";  public int UploadTotalKb = 5120;  public int UploadSingleKb = 1024;   public PlaceHolder MainPlaceHolder;  public PlaceHolder FolderPlaceHolder;  public PlaceHolder FilePlaceHolder;  public PlaceHolder EditBoxPlaceHolder;   public Label NavigatorLabel;  public Label DebugLabel;  public Label InfoLabel;  public Label FooterLabel;   public DataList FolderDataList;  public DataList FileDataList;   public GeneralEventDelegate MoveFileInFolderDelegate;  public GeneralEventDelegate MoveFileToRootDelegate;  public GeneralEventDelegate MoveFileToParentDelegate;  //-----------------------------------end public variable   //-----------------------------------begin private variable  private string XmlFilePath = "";  private string CurrentPath = "";  private string ManageRoot_Phs = "";  private string SiteRoot = "";   private string FilePathSession = "flMngFileCurPath";  private string FolderPathSession = "flMngCurPath";  //-----------------------------------end private variable   //-----------------------------------begin public method  public void Go()  {   if(MainPlaceHolder==null)return;      if(InfoLabel!=null)InfoLabel.Text="";   if(DebugLabel!=null)DebugLabel.Text="";   if(NavigatorLabel!=null)NavigatorLabel.Text="";      if(!ProgramRoot.EndsWith("/")) ProgramRoot+="/";   XmlFilePath = HttpContext.Current.Server.MapPath(ProgramRoot+"user.xml");      string reqPath = HttpContext.Current.Request.QueryString["path"]+"";   reqPath = HttpContext.Current.Server.UrlDecode(reqPath);   if(reqPath==""|reqPath.IndexOf(ManageRoot)!=0)   {    CurrentPath = HttpContext.Current.Server.MapPath(ManageRoot);   }   else   {    CurrentPath = HttpContext.Current.Server.MapPath(reqPath);   }   ManageRoot_Phs = HttpContext.Current.Server.MapPath(ManageRoot);   SiteRoot = HttpContext.Current.Server.MapPath("/");       if(Debug&DebugLabel!=null)   {    DebugLabel.Text+="/n<li/>SiteRoot: "+SiteRoot;    DebugLabel.Text+="/n<li/>ManageRoot_Phs: "+ManageRoot_Phs;    DebugLabel.Text+="/n<li/>CurrentPath: "+CurrentPath;    DebugLabel.Text+="/n<hr/>";   } // end if 1      Navigator(reqPath);      if(Verify)   {    bool login = CheckPermission();        if(Debug&DebugLabel!=null)    {     DebugLabel.Text+="<li/>LoginSession: "+login;     DebugLabel.Text+="<hr/>";    }    switch(HttpContext.Current.Request.QueryString["id"]+"")    {     case "logout":      HttpContext.Current.Session.Abandon();      GoBack("已登出系统 ", 3, LogoutGotoUrl, InfoLabel);      return;     case "editinfo":      EditBox(MainPlaceHolder, new EventHandler(EditInfo));      return;    }        if(Debug&DebugLabel!=null)    {     DebugLabel.Text+="/n<li/>XmlFilePath: "+XmlFilePath;     DebugLabel.Text+="/n<li/>是否已登陆: "+login;     DebugLabel.Text+="/n<li/>Session[/"sqFlMngLogin/"]: "+      HttpContext.Current.Session["sqFlMngLogin"];     DebugLabel.Text+="/n<hr/>";    } // end if 1        if(login)    {     Main();    }    else    {     LoginBox(MainPlaceHolder, new EventHandler(CheckLogin));     return;    }   }    else   {    Main();   }// end if   Footer();  } // end Go;  //-----------------------------------end public method   //-----------------------------------begin private method   private void EditInfo(Object s, EventArgs e)  {   String Username=HttpContext.Current.Request.Form["Username"]+"";   String Password=HttpContext.Current.Request.Form["Password"]+"";   String RePassword=HttpContext.Current.Request.Form["RePassword"]+"";   String CheckCode=HttpContext.Current.Request.Form["CheckCode"]+"";   String CheckCodeSession=HttpContext.Current.Session["sqFlMngCheckCode"]+"";      if(Debug&&DebugLabel!=null)   {    DebugLabel.Text+="<li/>"+Username;    DebugLabel.Text+="<li/>"+Password;    DebugLabel.Text+="<li/>"+CheckCode;    DebugLabel.Text+="<li/>"+CheckCodeSession;    DebugLabel.Text+="<hr/>";   }   if(CheckCode!=CheckCodeSession)   {    Message("验证码错误!", InfoLabel);    goto Error;   }    if(Username=="")   {    Message("用户名不能为空!", InfoLabel);    goto Error;   }      Finished:;      string RootPath=HttpContext.Current.Server.MapPath(ProgramRoot);   if(!RootPath.EndsWith("//"))RootPath+="//";      String FilePath=RootPath+"user.xml";   DataSet dsDataSet=new DataSet();   DataTable dtConfig=new DataTable();      dsDataSet.ReadXml(FilePath);   dtConfig=dsDataSet.Tables["Admin"];      dtConfig.Rows[0]["Username"]=Username;      if(Password!="")   {    if(Password!=RePassword)    {     Message("密码与确认密码不相同, 操作被终止!", InfoLabel);     return;    }    dtConfig.Rows[0]["Password"]=md5(Password);   }        dsDataSet.WriteXml(FilePath);      dsDataSet.Dispose();   dtConfig.Dispose();      HttpContext.Current.Session.Abandon();   GoBack("数据已更新, 请重新登陆, 3 秒后返回, 还有 ", 3, "?", InfoLabel);      goto End;      Error:;      goto End;      End:;  }   private void Message(String word, Label InfoLabel)  {   if(InfoLabel==null)return;   InfoLabel.Text="<div style=/"display:table;width:100%;background-color:yellow!important;"+     "color:black!important;text-align:center!important;/">"+     word+"</div>";  }   private void EditBox(PlaceHolder EditBoxPh, EventHandler SubmitEventHandler)  {   if(EditBoxPh==null)goto End;      string RootPath=HttpContext.Current.Server.MapPath(ProgramRoot);   if(!RootPath.EndsWith("//"))RootPath+="//";   DataSet dsDataSet=new DataSet();   DataTable dtConfig=new DataTable();      dsDataSet.ReadXml(RootPath+"user.xml");   dtConfig=dsDataSet.Tables["Admin"];         Literal Br=new Literal();   Br.Text="<br/>";      Literal Reset=new Literal();   Reset.Text=    " <input type=/"reset/" value=/"reset/" onclick=/"return confirm('现在重置吗?');/" />";      Literal ltUsername=new Literal();   ltUsername.Text="username: ";    TextBox Username=new TextBox();   Username.ID="Username";   Username.Text=dtConfig.Rows[0]["Username"]+"";      Literal ltPassword=new Literal();   ltPassword.Text="<br/>password: ";    TextBox Password=new TextBox();   Password.ID="Password";   Password.TextMode=TextBoxMode.Password;    Literal ltRePassword=new Literal();   ltRePassword.Text="<br/>re-password: ";      TextBox RePassword=new TextBox();   RePassword.ID="RePassword";   RePassword.TextMode=TextBoxMode.Password;      Literal ltPublished=new Literal();   ltPublished.Text="(不更改密码请保留为空)<br/>Published: ";   Literal ltCheckCode=new Literal();   ltCheckCode.Text="<br/>CheckCode: ";      TextBox CheckCode=new TextBox();   CheckCode.ID="CheckCode";   CheckCode.Columns=4;      Button smtButton=new Button();   smtButton.ID="glySubmit";   smtButton.Text="Edit Now";   smtButton.Click += SubmitEventHandler;   smtButton.Attributes["onclick"]="javascript:return confirm('请确认更改?')";      System.Web.UI.WebControls.Image CheckCodeImage=new System.Web.UI.WebControls.Image();   CheckCodeImage.ImageUrl="cs/checkcode.aspx";      EditBoxPh.Controls.Add(ltUsername);     EditBoxPh.Controls.Add(Username);   EditBoxPh.Controls.Add(ltPassword);     EditBoxPh.Controls.Add(Password);   EditBoxPh.Controls.Add(ltRePassword);     EditBoxPh.Controls.Add(RePassword);   EditBoxPh.Controls.Add(ltCheckCode);   EditBoxPh.Controls.Add(CheckCode);   EditBoxPh.Controls.Add(CheckCodeImage);   EditBoxPh.Controls.Add(Br);   EditBoxPh.Controls.Add(smtButton);   EditBoxPh.Controls.Add(Reset);      dtConfig.Dispose();   dsDataSet.Dispose();      End:;  }   private void Footer()  {   if(FooterLabel==null)return;      FooterLabel.Text=auSubject+" "+auVersion+", Powered by "+au+".";   FooterLabel.Text+="<br/>© 2007-2008, "+au+" All rights reserved.";  }   private void Main()  {   GetFolderBar(FolderPlaceHolder);      switch(HttpContext.Current.Request.QueryString["id"]+"")   {    case "upload":     Upload();     return;    case "editfile":     EditFileBox(EditBoxPlaceHolder);     return;   }      ListDirectorys(CurrentPath, ManageRoot_Phs, FolderDataList);   ListFile(CurrentPath, ManageRoot_Phs, FileDataList);   GetFileBar(FilePlaceHolder);  }   private void EditFileBox(PlaceHolder ph)  {   if(ph==null)return;      bool Debug =false;      string filePath = HttpContext.Current.Request.QueryString["filePath"]+"";   string fileName = Path.GetFileName(filePath);   string fileExt = Path.GetExtension(fileName);   string finalPath = HttpContext.Current.Server.MapPath(filePath);      if(Debug&DebugLabel!=null)   {    DebugLabel.Text += "<li/>Edit File:";    DebugLabel.Text += "<li/>filePath: "+filePath;    DebugLabel.Text += "<li/>fileName: "+fileName;    DebugLabel.Text += "<li/>fileExt: "+fileExt;    DebugLabel.Text += "<li/>finalPath: "+finalPath;    DebugLabel.Text += "<li/>CheckPathIn(filePath, ManageRoot, true): "+     CheckPathIn(filePath, ManageRoot, true);    DebugLabel.Text += "<li/>CheckExtension(EditableExtension, fileExt): "+     CheckExtension(EditableExtension, fileExt);   }      if(filePath=="")   {     GoBack("文件名不能为空, 3 秒后返回, 还有 ", 3, true, InfoLabel);    return;   }      if(!CheckPathIn(filePath, ManageRoot, true))   {    GoBack("越权, 操作被终止, 3 秒后返回, 还有 ", 3, true, InfoLabel);    return;   }      if(fileName.IndexOf(".")<0)   {    GoBack("文件名必须有后缀, 3 秒后返回, 还有 ", 3, true, InfoLabel);    return;   }      if(!CheckExtension(EditableExtension, fileExt))   {    GoBack("不允许编辑的文件类型, 3 秒后返回, 还有 ", 3, true, InfoLabel);    return;     }      if(!File.Exists(finalPath))   {    GoBack("文件不存在, 操作被终止, 3 秒后返回, 还有 ", 3, false, InfoLabel);    return;     }      HtmlInputHidden hih = new HtmlInputHidden();    hih.Value = finalPath;    hih.ID = "flMngEditFilePath";   ph.Controls.Add(hih);       Literal ltl;      ltl = new Literal();   ltl.Text = "<li/>正在编辑文件: <b>"+filePath+"</b><br/>";   ph.Controls.Add(ltl);        TextBox tbx = new TextBox();    tbx.TextMode = TextBoxMode.MultiLine;    tbx.Columns = 60;    tbx.Rows = 20;    tbx.Text = ReadTextFile(finalPath);    tbx.ID = "flMngEditFileContent";   ph.Controls.Add(tbx);      ltl = new Literal();   ltl.Text = "<br/>";   ph.Controls.Add(ltl);      Button btn = new Button();    btn.Text = "Submit";    btn.Attributes["onclick"] = "javascript: return confirm('确定更改?')";    btn.Click += new EventHandler(EditFileChange);   ph.Controls.Add(btn);      ltl = new Literal();   ltl.Text = " <input type='reset' value='reset' onclick=/"return confirm('是否重置?');/"";   ph.Controls.Add(ltl);     } // end private void EditFileBox   private void EditFileChange(Object s, EventArgs e)  {   bool Debug=false;   string finalPath = HttpContext.Current.Request.Form["flMngEditFilePath"]+"";   string fileContent = HttpContext.Current.Request.Form["flMngEditFileContent"]+"";      if(Debug&InfoLabel!=null)   {    InfoLabel.Text+="<li/>finalPath: "+finalPath;    InfoLabel.Text+="<li/>finalPath: "+fileContent;   }      WriteTextFile(finalPath, fileContent);      GoBack("文件更新完毕, 3 秒后返回, 还有 ", 3, true, InfoLabel);   return;    }   private void WriteTextFile(string fileName, string content)  {   using(StreamWriter sw = new StreamWriter(fileName))   {    sw.Write(content);   }  } // end private void WriteTextFile   private string ReadTextFile(string filePath)  {   if(!File.Exists(filePath))return "false";   string fileString="";   using(StreamReader sr = new StreamReader(filePath))   {    fileString = sr.ReadToEnd();   }   return fileString;  } // end private string ReadTextFile   private bool CheckExtension(string extList, string extForCheck)  {   return Regex.IsMatch(    extList,     @extForCheck.Replace(".","//.")+"//b",     RegexOptions.IgnoreCase    );  } // end private bool CheckExtension   private bool CheckPathIn(string pathIn, string pathForCheck)  {    if(pathIn.IndexOf(pathForCheck)<0)return false;   return true;  }   private bool CheckPathIn(string pathIn, string pathForCheck, bool CovPath)  {   if(CovPath)   {    pathIn = HttpContext.Current.Server.MapPath(pathIn);    pathForCheck = HttpContext.Current.Server.MapPath(pathForCheck);   }      return CheckPathIn(pathIn, pathForCheck);  }   private void GetFileBar(PlaceHolder ph)  {   if(ph==null)return;      Literal ltr = new Literal();   ltr.Text="<h3>文件操作:</h3>";   ph.Controls.Add(ltr);      LinkButton lbtn;      lbtn = new LinkButton();   lbtn.Text = "MoveTo Root | ";   lbtn.Attributes["onclick"] = "javascript:return confirm('确定要移动文件到根目录吗?');";   if(MoveFileToRootDelegate!=null)   lbtn.Click+=new EventHandler(MoveFileToRootDelegate);   ph.Controls.Add(lbtn);      lbtn = new LinkButton();   lbtn.Text = "MoveTo Parent | ";   lbtn.Attributes["onclick"] = "javascript:return confirm('确定要移动文件到父目录吗?');";   if(MoveFileToParentDelegate!=null)   lbtn.Click+=new EventHandler(MoveFileToParentDelegate);   ph.Controls.Add(lbtn);      lbtn = new LinkButton();   lbtn.Text = "Move File In: ";   lbtn.Attributes["onclick"] = "javascript:return confirm('确定要移动文件吗?');";   if(MoveFileInFolderDelegate!=null)   lbtn.Click+=new EventHandler(MoveFileInFolderDelegate);   ph.Controls.Add(lbtn);     }   private void GetFolderBar(PlaceHolder ph)  {   if(ph==null)return;   Literal ltl;      LinkButton lbtn = new LinkButton();   lbtn.Text="New Directory";   lbtn.Click += new EventHandler(CreateNewDirectory);   lbtn.Attributes["onclick"] = "return confirm('现在创建新文件夹吗?')";   ph.Controls.Add(lbtn);      ltl = new Literal();   ltl.Text=" | ";   ph.Controls.Add(ltl);      LinkButton lbtnNewFile = new LinkButton();   lbtnNewFile.Text="New File(txtfile)";   lbtnNewFile.Click += new EventHandler(CreateNewFile);   lbtnNewFile.Attributes["onclick"] = "return confirm('现在创建新文件吗?')";   ph.Controls.Add(lbtnNewFile);      ltl = new Literal();   ltl.Text=": ";   ph.Controls.Add(ltl);      TextBox tbx = new TextBox();   tbx.ID = "flMngCreateNewFolderInCurrent";   ph.Controls.Add(tbx);      string QueryUrl="";   AutoConvertPagedUrl("id", out QueryUrl);    ltl = new Literal();   ltl.Text = " <a href='"+QueryUrl+"upload'>upload</a>";      ph.Controls.Add(ltl);  }   private void ListFile(string path, string pathForCheck, DataList dl)  {   if(path.IndexOf(pathForCheck)<0|dl==null)return;      DirectoryInfo di = new DirectoryInfo(path);   FileInfo[] fiArray = di.GetFiles();      int TotalFile = fiArray.Length;      if(TotalFile==0)   {    InfoLabel.Text+="<h2 class='algc'>当前目录没有文件.</h2>";    HttpContext.Current.Session[FileListSession] = null;    return;   }      if(Debug&DebugLabel!=null)   {    DebugLabel.Text+="<li/>TotalFiles: "+TotalFile;         DebugLabel.Text+="<hr/>";   }      if(HttpContext.Current.Session[FileListSession]==null|    HttpContext.Current.Session[FilePathSession]+""!=path)   {       DataTable dt = new DataTable();    DataRow dr;        CreateDataColumn(dt, "FileName", typeof(string));    CreateDataColumn(dt, "FileRelativePath", typeof(string));    CreateDataColumn(dt, "FilePhysicalPath", typeof(string));        for(int i=0, j=fiArray.Length; i<j; i++)    {     string FilePath = fiArray[i].FullName+"";     ConvertPathToRelative(ref FilePath);;          dr = dt.NewRow();     dr[0]=fiArray[i].Name;     dr[1]=FilePath;     dr[2]=fiArray[i].FullName;     dt.Rows.Add(dr);    }    dl.DataSource = dt.DefaultView;    dl.DataBind();    HttpContext.Current.Session[FileListSession] = dt;    HttpContext.Current.Session[FilePathSession] = path;   }   else    {    HttpContext.Current.Session[FilePathSession] = path;   }  } // end private void ListFile   private void ListDirectorys(string path, string pathForCheck, DataList dl)  {    if(path.IndexOf(pathForCheck)<0|dl==null)return;      if(HttpContext.Current.Session[FolderListSession]==null|    HttpContext.Current.Session[FolderPathSession]+""!=path)   {    if(Debug&DebugLabel!=null)    {     DebugLabel.Text+="<li/>Session[/"FolderPathSession/"]: "+      HttpContext.Current.Session[FolderPathSession];           DebugLabel.Text+="<hr/>";    }        DirectoryInfo di = new DirectoryInfo(path);    DirectoryInfo[] diArray = di.GetDirectories();        if(diArray.Length==0)    {     InfoLabel.Text+="<h2 class='algc'>当前目录没有子目录.</h2>";     HttpContext.Current.Session[FolderListSession] = null;     //return;    }        DataTable dt = new DataTable();    DataRow dr;        CreateDataColumn(dt, "FolderName", typeof(string));    CreateDataColumn(dt, "FolderRelativePath", typeof(string));    CreateDataColumn(dt, "FolderPhysicalPath", typeof(string));        for(int i=0, j=diArray.Length; i<j; i++)    {     string FolderPath = diArray[i].FullName+"";     ConvertPathToRelative(ref FolderPath, true);          dr = dt.NewRow();     dr[0]=diArray[i].Name;     dr[1]=FolderPath;     dr[2]=diArray[i].FullName;     dt.Rows.Add(dr);    }    dl.DataSource = dt.DefaultView;    dl.DataBind();    HttpContext.Current.Session[FolderListSession] = dt;    HttpContext.Current.Session[FolderPathSession] = path;   }   else    {    HttpContext.Current.Session[FolderPathSession] = path;   }  }   private void Upload()  {   if(EditBoxPlaceHolder==null)return;   string QueryUrl="";   AutoConvertPagedUrl("id", out QueryUrl);    string uploadPath = HttpContext.Current.Request.QueryString["path"]+"";   if(uploadPath=="")uploadPath = ManageRoot;   upload up=new upload();   up.ext=UploadExtension;   up.debug=false;   up.item=5;                      // 声明显示多少个上传框   up.path=uploadPath;            // 上传目录;   up.goback_url=QueryUrl+"upload";   // 上传完毕后返回的 URL   up.goback_second=5;             // 上传后返回间隔   up.interval=5;                  // 每次上传间隔, 单位秒   up.autorename=true;             // 自动重命名;      up.totalsize = UploadTotalKb;   up.singlesize = UploadSingleKb;      // 声明 处理 所有 返回路径 的方法   //up.ReturnFilePath=new OneArgStringDelegate(GetPath);      up.UploadPh=EditBoxPlaceHolder;           // 声明显示上传控件的占位符   up.UploadBox();                 // 显示上传操作控件      up=null;  }   private void AutoConvertPagedUrl(String QueryId, out String QueryUrl)  {   QueryUrl=System.Web.HttpContext.Current.Request.Url+"";      if(QueryUrl.IndexOf(@"?")==-1)   {    QueryUrl+=@"?";   }   QueryUrl=Regex.Replace(QueryUrl,@"/b"+@QueryId+@"/=[^&]+","", RegexOptions.IgnoreCase);   QueryUrl+="&"+QueryId+"=";   QueryUrl=Regex.Replace(QueryUrl,@"/?/&",@"?", RegexOptions.IgnoreCase);   QueryUrl=Regex.Replace(QueryUrl,@"/&+",@"&", RegexOptions.IgnoreCase);      string sReferrer = System.Web.HttpContext.Current.Request.UrlReferrer+"";   if(sReferrer.IndexOf("(")>-1&&sReferrer.IndexOf(")")>-1)   {    sReferrer = Regex.Replace(sReferrer, @".*(/(.*/)).*", "$1");    QueryUrl = Regex.Replace(     QueryUrl, @"(http/:.*?//)", "$1"+sReferrer+"/", RegexOptions.IgnoreCase);   }  } // end private void AutoConvertPagedUrl  //-----------------------------------end private method   private void CreateNewFile(Object s, EventArgs e)  {   Control ctlPh = FolderPlaceHolder.FindControl("flMngCreateNewFolderInCurrent");   if(ctlPh!=null)   {    TextBox tbx = (TextBox)ctlPh;    if(tbx.Text!="")    {     string finalFileName = CurrentPath+tbx.Text;          if(Debug&DebugLabel!=null)     {      DebugLabel.Text+="<li/>new file string:"+tbx.Text;      DebugLabel.Text+="<li/>finalFileName:"+finalFileName;            DebugLabel.Text+="<hr/>";     }          if(tbx.Text.IndexOf(".")<0)     {      GoBack("新文件必须有扩展名, 操作被取消, 3 秒反返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", InfoLabel);       return;     }          if(File.Exists(finalFileName))     {      GoBack("文件已存在, 操作被取消, 3 秒反返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", InfoLabel);       return;     }     else     {      using(StreamWriter sw = new StreamWriter(finalFileName))      {            }      HttpContext.Current.Session[FileListSession] = null;      GoBack("新文件已创建, 3 秒反返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", InfoLabel);       return;     }    }   }  }   private void CreateNewDirectory(Object s, EventArgs e)  {   Control ctlPh = FolderPlaceHolder.FindControl("flMngCreateNewFolderInCurrent");   if(ctlPh!=null)   {    TextBox tbx = (TextBox)ctlPh;    if(tbx.Text!="")    {     string newFolder = CurrentPath+tbx.Text;     if(!Directory.Exists(newFolder))     {      Directory.CreateDirectory(newFolder);      HttpContext.Current.Session[FolderListSession] = null;      GoBack("新文件夹已创建, 3 秒反返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", InfoLabel);       return;     }     else     {      GoBack("文件夹已存在, 操作被取消, 3 秒反返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", InfoLabel);       return;     }    }   }  }   private StringBuilder GetPath(String PathQuery, String LinkString)  {   PathQuery=System.Web.HttpContext.Current.Server.UrlDecode(PathQuery);   if(!PathQuery.EndsWith("/"))PathQuery+="/";   StringBuilder sb=new StringBuilder();   String[] PathTemp=PathQuery.Split('/');   for(Int32 i=0, j=PathTemp.Length; i<j; i++)   {    if(PathTemp[i]!="")    {     sb.Append(" -> ");     if(i==j-2)     {      sb.Append("[");     }     sb.Append("<a href=/""+LinkString);     sb.Append("/");     for(Int32 k=0; k<=i; k++)     {        if(PathTemp[k]!="")      {       sb.Append(System.Web.HttpContext.Current.Server.UrlEncode(PathTemp[k]));       sb.Append("/");      }     }     sb.Append("/">");     sb.Append(PathTemp[i]);     sb.Append("</a>");     if(i==j-2)     {      sb.Append("]");     }    }   }   return sb;  } // end private StringBuilder GetPath    protected void CreateDataColumn(DataTable dt, String fieldName, Type tp)  {   dt.Columns.Add(new DataColumn(fieldName, tp));  }   protected void CreateDataColumn(DataTable dt, String fieldName)  {   dt.Columns.Add(new DataColumn(fieldName, typeof(int)));  }    private void ConvertPathToRelative(ref string FolderPath)  {   string SiteRoot= HttpContext.Current.Server.MapPath("/");      FolderPath = FolderPath.Replace(SiteRoot, "").Replace(@"/", "/");   if(!FolderPath.StartsWith("//"))FolderPath="/"+FolderPath;   FolderPath = HttpContext.Current.Server.UrlPathEncode(FolderPath);  }    private void ConvertPathToRelative(ref string FolderPath, bool plusSlash)  {   ConvertPathToRelative(ref FolderPath);      if(plusSlash)   if(!FolderPath.EndsWith("//"))FolderPath+="/";  }   private void Navigator(string curPath)  {   if(NavigatorLabel==null)return;      if(Debug&DebugLabel!=null)   {    DebugLabel.Text+="/n<li/>NavigatorLable ok. ";    DebugLabel.Text+="/n<hr/>";   }      NavigatorLabel.Text+="/n<div class='algr flMngNavigator'>/n";      bool login = CheckPermission();      if(!Verify|login)   {     bool mode=false;    if(login) mode=true;         NavigatorMethod(curPath, mode);   }      NavigatorLabel.Text+="/n</div>";  } // end public void Navigator   private void NavigatorMethod(string curPath, bool loginMode)  {   NavigatorLabel.Text+=    "<div class='fltl algl'>"+    "<a href='?path="+ManageRoot+"'>sqFlMng Root</a> "+    GetPath(curPath, "?path=")+    "</div> ";       if(loginMode)   {    NavigatorLabel.Text+=" <a href='?id=editinfo'>EditInfo</a>";    NavigatorLabel.Text+=" <a href='?id=logout'>logout</a>";   }  }   private bool CheckPermission()  {   DataTable dt = ReadDataSetTable(XmlFilePath, "Admin");    if(dt==null)    return false;        string login = HttpContext.Current.Session[LoginSession]+"";        if(login=="") return false;    return true;  } // end private bool CheckPermission   private DataTable ReadDataSetTable(string filePath, string tableName)  {   DataSet ds = new DataSet();    ds.ReadXml(filePath);   return ds.Tables[tableName];  } // end private DataTable ReadDataSetTable   private void LoginBox(PlaceHolder EditBoxPh, EventHandler SubmitEventHandler)  {   if(EditBoxPh==null)goto End;      Literal Br=new Literal();   Br.Text="<br/>";      Literal ltUsername=new Literal();   ltUsername.Text="Username: ";      Literal ltPassword=new Literal();   ltPassword.Text="<br/>Password: ";      Literal ltCheckCode=new Literal();   ltCheckCode.Text="<br/>CheckCode: ";      TextBox Username=new TextBox();   Username.ID="Username";      TextBox CheckCode=new TextBox();   CheckCode.ID="CheckCode";   CheckCode.Columns=4;      TextBox Password=new TextBox();   Password.TextMode=TextBoxMode.Password;   Password.ID="Password";      Button smtButton=new Button();   smtButton.ID="glySubmit";   smtButton.Text="login now";   smtButton.Click += SubmitEventHandler;   smtButton.Attributes["onclick"]="javascript:return confirm('现在登陆吗?')";      Literal Reset=new Literal();   Reset.Text=" <input type=/"reset/" value=/"reset/" "+    "onclick=/"return confirm('现在重置吗');/" />";      System.Web.UI.WebControls.Image CheckCodeImage=new System.Web.UI.WebControls.Image();   CheckCodeImage.ImageUrl="cs/checkcode.aspx";      EditBoxPh.Controls.Add(ltUsername);   EditBoxPh.Controls.Add(Username);   EditBoxPh.Controls.Add(ltPassword);   EditBoxPh.Controls.Add(Password);   EditBoxPh.Controls.Add(ltCheckCode);   EditBoxPh.Controls.Add(CheckCode);   EditBoxPh.Controls.Add(CheckCodeImage);   EditBoxPh.Controls.Add(Br);   EditBoxPh.Controls.Add(smtButton);   EditBoxPh.Controls.Add(Reset);      End:;  }   private void CheckLogin(Object s, EventArgs e)  {  String Username=HttpContext.Current.Request.Form["Username"]+"";  String Password=HttpContext.Current.Request.Form["Password"]+"";   Password=md5(Password);  String CheckCode=HttpContext.Current.Request.Form["CheckCode"]+"";  String CheckCodeSession_=HttpContext.Current.Session[CheckCodeSession]+"";   if(CheckCode!=CheckCodeSession_)  {   GoBack("验证码不正确, 3秒后返回, 还有 ", 3,     HttpContext.Current.Request.Url+"", InfoLabel);   goto Error;  }    string RootPath=HttpContext.Current.Server.MapPath(ProgramRoot);   if(!RootPath.EndsWith("//"))   {     RootPath+="//";   }   DataSet dsDataSet=new DataSet();   DataTable dtConfig=new DataTable();    dsDataSet.ReadXml(XmlFilePath);   dtConfig=dsDataSet.Tables["Admin"];      DataRow[] drArray;        drArray = dtConfig.Select("Username = '"+Username+"'");      if(drArray.Length==0)   {    GoBack("用户名错误, 3秒后返回, 还有 ", 3,      HttpContext.Current.Request.Url+"", InfoLabel);    return;   }       drArray = dtConfig.Select("Username = '"+Username     +"' and Password = '"+Password+"'");        if(drArray.Length==0)   {    GoBack("密码错误, 3秒后返回, 还有 ", 3,      HttpContext.Current.Request.Url+"", InfoLabel);     return;   }      HttpContext.Current.Session[LoginSession]="ok";   GoBack("登陆成功, 3秒后返回, 还有 ", 3, "?", InfoLabel);   return;      Error:;   End:;  }   private void GoBack(String sPrompt, Int32 iSecond, String sUrl, Label GobackLabel)  {   if(GobackLabel==nullreturn;   GobackLabel.Text+="<script type=/"text/javascript/">/n";   GobackLabel.Text+="//<![CDATA[/n";   GobackLabel.Text+=var temp=onload;/n";   GobackLabel.Text+=onload=function(){/n";   GobackLabel.Text+="  try{temp()}catch(e){}/n";   GobackLabel.Text+="  fTimer("+iSecond+",'timer', 10);/n";   GobackLabel.Text+=" }/n";   GobackLabel.Text+="  function fTimer(iTimestamp, sId, iMs){/n";   GobackLabel.Text+="  if(!(iTimestamp.constructor==Date)){/n";   GobackLabel.Text+="   var sqTimeStamp=new Date();/n";   GobackLabel.Text+="   sqTimeStamp.setSeconds(sqTimeStamp.getSeconds()+iTimestamp);/n";   GobackLabel.Text+="   iTimestamp=sqTimeStamp;/n";   GobackLabel.Text+="  }/n";   GobackLabel.Text+="    var tl=arguments.callee;/n";   GobackLabel.Text+="    if(typeof sId=='string'){/n";   GobackLabel.Text+="   var oEle=document.getElementById(sId);/n";   GobackLabel.Text+="  } else {/n";   GobackLabel.Text+="   var oEle=sId;/n";   GobackLabel.Text+="  }/n";   GobackLabel.Text+="  var dt=new Date();/n";   GobackLabel.Text+="  var iCk=((iTimestamp.getTime()-dt.getTime())/1000).toFixed(3);/n";   GobackLabel.Text+="  if(iCk<=0){/n";   GobackLabel.Text+="   oEle.innerHTML='00.000';/n";   GobackLabel.Text+="   return false;/n";   GobackLabel.Text+="  } else {/n";   GobackLabel.Text+="   oEle.innerHTML=iCk;/n";   GobackLabel.Text+="   var iTimer=setTimeout(function(){tl(iTimestamp, oEle, iMs)},iMs); /n";   GobackLabel.Text+="  }/n";   GobackLabel.Text+=" } // end function fTimer // shawl.qiu script/n";   GobackLabel.Text+="//]]>/n";   GobackLabel.Text+="</script>/n";   GobackLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset=utf-8/" />";   GobackLabel.Text+="<meta http-equiv=/"refresh/" content=/""+iSecond+";URL="+sUrl+"/">";   GobackLabel.Text+="<div style=/"display:table;width:100%;background-color:yellow!important;"+     "color:black!important;text-align:center!important;/">"+     sPrompt+", <span id='timer'>"+iSecond+"</span>秒 后返回.</div>";  }   private void GoBack(String sPrompt, Int32 iSecond, bool byReferrer, Label GobackLabel)  {   if(GobackLabel==null)return;   string url = "?";   if(byReferrer) url = HttpContext.Current.Request.UrlReferrer+"";   GoBack(sPrompt, iSecond, url, GobackLabel);  }   private String md5(String sMd5)  {   return System.Web.Security.FormsAuthentication.    HashPasswordForStoringInConfigFile(sMd5, "MD5");  } } //---------------------------------------------------------------------end class FileManager  3. 页面代码 <%@ Page Language="C#AutoEventWireup="True" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Collections" %> <%@ import Namespace="System.IO" %> <%@ import Namespace="System.Text.RegularExpressions" %> <%@ import Namespace="System.Web.UI.HtmlControls" %> <%@ Assembly src="cs/FileManager.cs" %> <%@ Assembly src="cs/sqNS.cs" %> <%@ import Namespace="SQ" %> <script runat="server">  /* Start flMng Global setting */   public bool Debug = false;      public bool DebugFile = false;      public string ManageRoot="/test/";      public string LoginSession = "sqFlMngLogin";    public string FolderListSession = "flMngVsFolderList";   public string FileListSession = "flMngVsFileList";     /* End flMng Global setting */  void Page_Load(Object s, EventArgs e)  {   FileManager flMng = new FileManager();       flMng.Debug = Debug;                 // 是否为调试模式         flMng.Verify = true;                // 是否起用验证    flMng.LoginSession = LoginSession;// 声明验证是否登陆的 Session 项(不为空则认为已登陆)    flMng.FolderListSession = FolderListSession;    flMng.FileListSession = FileListSession;        flMng.ManageRoot = ManageRoot;        // 要管理的文件目录    flMng.ProgramRoot = "/sqFlMng/";    // 本程序所在目录        flMng.LoginGotoUrl = "?";    flMng.LogoutGotoUrl = "?";        flMng.UploadExtension = "7z,rar,zip,mp3,bmp,gif,jpg,jpeg,png,txt,swf";    flMng.UploadTotalKb = 5120;    flMng.UploadSingleKb = 1024;        flMng.EditableExtension = ".txt|.asp|.aspx|.ascx|.html|.htm|.xml|.xsl|.xslt|.xsd|.dtd|"+    ".css|.vbs|.js|.svg|.c|.rss|.wml|.w3d";     flMng.DebugLabel = flMngDebugLabel;    flMng.NavigatorLabel = flMngNavigatorLabel;    flMng.InfoLabel = flMngInfoLabel;    flMng.FooterLabel = flMngFooter;        flMng.MainPlaceHolder = flMngPh;        flMng.FolderPlaceHolder = flMngFolderPh;    flMng.FilePlaceHolder = flMngFileBar;        flMng.EditBoxPlaceHolder = flMngEditBoxPh;        flMng.FolderDataList = flMngFolderList;    flMng.FileDataList = flMngFileList;        flMng.MoveFileInFolderDelegate = new GeneralEventDelegate(FileMoveFileMethod);    flMng.MoveFileToRootDelegate = new GeneralEventDelegate(FileMoveFileToRootMethod);    flMng.MoveFileToParentDelegate = new GeneralEventDelegate(FileMoveFileToParentMethod);           flMng.Go();      flMng=null      string QueryId = Request.QueryString["id"]+"";      switch(QueryId)   {    case "editinfo":break;    case "editfile":break;    default:     if (!IsPostBack)     {      BindList(flMngFolderList, FolderListSession);      BindList(flMngFileList, FileListSession);            flMngFileMoveInListRbl.DataSource = (DataTable)Session[FolderListSession];      flMngFileMoveInListRbl.DataBind();     }     break;   }  } // end Page_Load   void BindList(DataList dl, string sessionName)   {   dl.DataSource = (DataTable)Session[sessionName];   dl.DataBind();  }   void flMngEditCmd(Object sender, DataListCommandEventArgs e)   {   DataList dl = (DataList)sender;   dl.EditItemIndex = e.Item.ItemIndex;   BindList(dl, FolderListSession);        string sForDelete =     ((HtmlInputHidden)(dl.Items[e.Item.ItemIndex].FindControl("flMngUpdateFolderHid"))).Value;      RadioButtonList rbl =    (RadioButtonList)(dl.Items[e.Item.ItemIndex].FindControl("flMngRdoBtnLst"));       DataTable dt = ((DataTable)Session[FolderListSession]).Copy();      DeleteTableRow(dt, "FolderRelativePath = '"+sForDelete+"'");       rbl.DataSource = dt;   rbl.DataBind();  }   void flMngFileEditCmd(Object sender, DataListCommandEventArgs e)   {   DataList dl = (DataList)sender;   dl.EditItemIndex = e.Item.ItemIndex;   BindList(dl, FileListSession);       RadioButtonList rbl =    (RadioButtonList)(dl.Items[e.Item.ItemIndex].FindControl("flMngFileRdoBtnLst"));       DataTable dt = ((DataTable)Session[FolderListSession]).Copy();   rbl.DataSource = dt;   rbl.DataBind();  }   private void DeleteTableRow(DataTable dt, string condition)  {   DataRow[] drArray = dt.Select(condition);      for(int i = 0; i< drArray.Length; i++)   {    drArray[i].Delete();   }  } // end private void DeleteTableRow   void flMngRenameFolderCmd(Object sender, DataListCommandEventArgs e)   {    string updateString = ((TextBox)e.Item.FindControl("flMngUpdateFolderTbx")).Text;   updateString = Regex.Replace(updateString, @"^/s+|/s+$", "");      string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;   folderString=HttpContext.Current.Server.UrlDecode(folderString);         if(updateString!="")   {    DirectoryInfo di = new DirectoryInfo(MapPath(folderString));        string destination = di.Parent.FullName+@"/"+updateString+@"/";        if(!Directory.Exists(destination))    {     di.MoveTo(destination);      Session[FolderListSession] = null;           Utility.GoBack("文件夹已重命名, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     return;    }    else    {     Utility.GoBack("已存在相同的文件夹, 本次操作被取消, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }   }   } // end void flMngUpdateFolderCmd   void flMngRenameFileCmd(Object sender, DataListCommandEventArgs e)   {    string updateString = ((TextBox)e.Item.FindControl("flMngRenameFileTbx")).Text;   updateString = Regex.Replace(updateString, @"^/s+|/s+$", "");      string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;   fileString=HttpContext.Current.Server.UrlDecode(fileString);      FileInfo fi = new FileInfo(MapPath(fileString));      string originalName = Path.GetFileName(fileString);   string parentPath = fi.DirectoryName+"//";      string originalPath = fi.FullName;   string finalPath = parentPath+updateString;      if(DebugFile)   {    HttpContext.Current.Response.Write("<li/>rename file");    HttpContext.Current.Response.Write("<li/>updateString: "+updateString);    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);    HttpContext.Current.Response.Write("<li/>original name: "+originalName);    HttpContext.Current.Response.Write("<li/>parentPath: "+parentPath);    HttpContext.Current.Response.Write("<li/>originalPath: "+originalPath);    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);        HttpContext.Current.Response.Write("<hr/>");   }      if(updateString == originalName)return;   if(!File.Exists(finalPath))   {    fi.MoveTo(finalPath);        Session[FileListSession] = null;         SQ.Utility.GoBack("文件已重命名, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    return;   }   else   {    SQ.Utility.GoBack("已存在相同的文件名, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }  } // end void flMngUpdateFolderCmd   void flMngNewFolderCmd(Object sender, DataListCommandEventArgs e)   {    string updateString = ((TextBox)e.Item.FindControl("flMngNewFolderTbx")).Text;   updateString = Regex.Replace(updateString, @"^/s+|/s+$", "");      string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;   folderString=HttpContext.Current.Server.UrlDecode(folderString);      if(updateString!="")   {    DirectoryInfo di = new DirectoryInfo(MapPath(folderString));        string destination = di.FullName+@"/"+updateString+@"/";           if(!Directory.Exists(destination))    {     Directory.CreateDirectory(destination);     Session[FolderListSession] = null;           Utility.GoBack("文件夹已创建, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);           return;    }    else    {     Utility.GoBack("已存在相同的文件夹, 本次操作被取消, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }   }   } // end void flMngUpdateFolderCmd   void flMngDeleteFolderCmd(Object sender, DataListCommandEventArgs e)   {   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;   folderString=HttpContext.Current.Server.UrlDecode(folderString);      DirectoryInfo di = new DirectoryInfo(MapPath(folderString));         if(di.Exists)   {    di.Delete(true);    Session[FolderListSession] = null;         SQ.Utility.GoBack("文件夹已删除, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);         return;   }   else   {    SQ.Utility.GoBack("文件夹不存在, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }  } // end void flMngUpdateFolderCmd   void flMngDeleteFileCmd(Object sender, DataListCommandEventArgs e)   {   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;   fileString=HttpContext.Current.Server.UrlDecode(fileString);      string finalPath = MapPath(fileString);      if(DebugFile&flMngDebugLabel!=null)   {    HttpContext.Current.Response.Write("<li/>delete file");    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);   }      if(File.Exists(finalPath))   {    File.Delete(finalPath);    Session[FileListSession] = null;         SQ.Utility.GoBack("文件已删除, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }  } // end void flMngUpdateFolderCmd   void flMngMoveFolderToRootCmd(Object sender, DataListCommandEventArgs e)   {   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;   folderString=HttpContext.Current.Server.UrlDecode(folderString);      DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));      DirectoryInfo diForMove = new DirectoryInfo(MapPath(folderString));      if(diRoot.FullName == diForMove.Parent.FullName+"//")   {    SQ.Utility.GoBack("该文件夹已在根目录, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }   else   {    try    {     diForMove.MoveTo(diRoot+diForMove.Name);     Session[FolderListSession] = null;     Utility.GoBack("文件夹已移到根目录, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }    catch(Exception ex)    {     Utility.GoBack("该文件夹已在根目录, 本次操作被取消, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }   }  } // end void flMngUpdateFolderCmd   void flMngMoveFileToRootCmd(Object sender, DataListCommandEventArgs e)   {   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;   fileString=HttpContext.Current.Server.UrlDecode(fileString);      DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));   FileInfo fi = new FileInfo(MapPath(fileString));      string finalPath = diRoot+fi.Name;      if(DebugFile)   {    HttpContext.Current.Response.Write("<li/>Move To Root");    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);    HttpContext.Current.Response.Write("<li/>diRoot FullName: "+diRoot.FullName);    HttpContext.Current.Response.Write("<li/>fi FullName: "+fi.FullName);    HttpContext.Current.Response.Write("<li/>fi FullName: "+fi.DirectoryName+"//");    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);        HttpContext.Current.Response.Write("<hr/>");   }      if(diRoot.FullName==fi.DirectoryName+"//")   {    SQ.Utility.GoBack("该文件已在根目录, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }   else   {    try    {     fi.MoveTo(finalPath);     Session[FileListSession] = null;     Utility.GoBack("文件已移到根目录, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }    catch(Exception ex)    {     Utility.GoBack("根目录存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }   }  } // end void flMngMoveFileToRootCmd   void flMngMoveFolderToParentCmd(Object sender, DataListCommandEventArgs e)   {   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;   folderString=HttpContext.Current.Server.UrlDecode(folderString);      DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));   DirectoryInfo diForMove = new DirectoryInfo(MapPath(folderString));   DirectoryInfo diParent = diForMove.Parent;      string moveToPath = diForMove.Parent.Parent.FullName+"//"+diForMove.Name;   if(diParent.FullName == moveToPath)   {    SQ.Utility.GoBack("已存在相同目录, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }   else   {    if(moveToPath.IndexOf(diRoot.FullName)<0)    {     Utility.GoBack("越权, 操作被取消, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     return;    }    try    {     diForMove.MoveTo(moveToPath);     Session[FolderListSession] = null;     Utility.GoBack("文件夹已移到父目录, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }    catch(Exception ex)    {    SQ.Utility.GoBack("已存在相同目录, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    }   }  } // end void flMngUpdateFolderCmd   void flMngMoveFileToParentCmd(Object sender, DataListCommandEventArgs e)   {   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;   fileString=HttpContext.Current.Server.UrlDecode(fileString);    DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));   FileInfo fi = new FileInfo(MapPath(fileString));   DirectoryInfo di = new DirectoryInfo(fi.DirectoryName);       string finalPath = di.Parent.FullName+"//"+fi.Name;      if(DebugFile)   {    HttpContext.Current.Response.Write("<li/>Move To Parent");    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);    HttpContext.Current.Response.Write("<li/>fi.FullName: "+fi.FullName);    HttpContext.Current.Response.Write("<li/>di.FullName: "+di.FullName);    HttpContext.Current.Response.Write("<li/>di.Parent.FullName: "+di.Parent.FullName);    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);    HttpContext.Current.Response.Write("<hr/>");   }      if(!File.Exists(finalPath))   {    if(finalPath.IndexOf(diRoot.FullName)<0)    {     Utility.GoBack("越权, 操作被取消, 3 秒后返回, 还有 ", 3,       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     return;    }    else    {     try     {      fi.MoveTo(finalPath);      Session[FileListSession] = null;      Utility.GoBack("文件已移到父目录, 3 秒后返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     }     catch(Exception ex)     {      Utility.GoBack("已存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     }    }   }   else   {    SQ.Utility.GoBack("已存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);   }  } // end void flMngUpdateFolderCmd   void flMngMoveFolderInCmd(Object sender, DataListCommandEventArgs e)   {   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;   folderString=HttpContext.Current.Server.UrlDecode(folderString);      RadioButtonList rbl =    ((RadioButtonList)e.Item.FindControl("flMngRdoBtnLst"));      DirectoryInfo diForMove = new DirectoryInfo(MapPath(folderString));   string forMovePath = MapPath(rbl.SelectedValue+diForMove.Name);      if(DebugFile)   {    HttpContext.Current.Response.Write("<li/>Move in folder: "+rbl.SelectedValue);    HttpContext.Current.Response.Write("<li/>current folder: "+folderString);    HttpContext.Current.Response.Write("<li/>move in: "+forMovePath);   }      if(rbl.SelectedValue=="")   {    SQ.Utility.GoBack("必须选择一个项目进行操作, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     return;   }       if(Directory.Exists(forMovePath))   {    SQ.Utility.GoBack("已存在相同目录, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     return;   }   else   {    diForMove.MoveTo(forMovePath);        Session[FolderListSession] = null;    SQ.Utility.GoBack("文件夹已成功移动, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    return;    }  } // end void flMngUpdateFolderCmd   void flMngMoveFileInCmd(Object sender, DataListCommandEventArgs e)   {   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;   fileString=HttpContext.Current.Server.UrlDecode(fileString);   RadioButtonList rbl =    ((RadioButtonList)e.Item.FindControl("flMngFileRdoBtnLst"));      FileInfo fi = new FileInfo(MapPath(fileString));      string finalPath = MapPath(rbl.SelectedValue)+fi.Name;      if(DebugFile)   {    HttpContext.Current.Response.Write("<li/>Move File In Folder");    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);    HttpContext.Current.Response.Write("<li/>rbl==null: "+(rbl==null));    HttpContext.Current.Response.Write("<li/>rbl.SelectedValue: "+rbl.SelectedValue);    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);   }      if(rbl.SelectedValue=="")   {    return;   }      if(File.Exists(finalPath))   {    SQ.Utility.GoBack("已存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);     return;   }   else   {    fi.MoveTo(finalPath);        Session[FileListSession] = null;    SQ.Utility.GoBack("文件已成功移动, 3 秒后返回, 还有 ", 3,      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    return;    }  } // end void flMngUpdateFolderCmd   void flMngDownloadFileCmd(Object sender, DataListCommandEventArgs e)   {   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;   fileString=HttpContext.Current.Server.UrlDecode(fileString);        Utility.DownloadFile(fileString, true);  } // end void flMngDownloadFileCmd    void flMngItemCmd(Object s, DataListCommandEventArgs e)  {   switch (e.CommandName+"")   {        case "NewSubFolder":     flMngNewFolderCmd(s, e);     break;        case "flMngRenameFolderLb":     flMngRenameFolderCmd(s, e);     break;         case "flMngDeleteFolder":     flMngMoveFolderToRootCmd(s, e);     break;         case "MoveFolderToRoot":     flMngMoveFolderToRootCmd(s, e);     break;         case "MoveFolderToParent":     flMngMoveFolderToParentCmd(s, e);     break;         case "MoveFolderIn":     flMngMoveFolderInCmd(s, e);     break;   }   return;  }   void flMngFileItemCmd(Object s, DataListCommandEventArgs e)  {   switch (e.CommandName+"")   {        case "flMngRenameFile":     flMngRenameFileCmd(s, e);     break;         case "flMngDeleteFile":     flMngDeleteFileCmd(s, e);     break;         case "MoveFileToRoot":     flMngMoveFileToRootCmd(s, e);     break;         case "MoveFileToParent":     flMngMoveFileToParentCmd(s, e);     break;         case "MoveFileIn":     flMngMoveFileInCmd(s, e);     break;         case "DownloadFile":     flMngDownloadFileCmd(s, e);     break;   }   return;  }   void FileMoveFileMethod(Object s, EventArgs e)  {   if(flMngFileMoveInListRbl.SelectedValue=="")return;      int totalCbx = flMngFileList.Items.Count;      ArrayList alError = new ArrayList();      for(int i=0; i<totalCbx; i++)   {    HtmlInputCheckBox hicb =     (HtmlInputCheckBox)((flMngFileList.Items[i]).FindControl("flMngFileCbx"));        if(hicb.Checked)    {     string finalPath = flMngFileMoveInListRbl.SelectedValue+"//"+Path.GetFileName(hicb.Value);     if(File.Exists(finalPath))     {      alError.Add(finalPath);     }     else     {      File.Move(hicb.Value, finalPath);     }    }   } // end for      if(alError.Count>0)   {    flMngInfoLabel.Text+=     "<h3 class='algc'>有 "+alError.Count+      "个 文件未能移动, 原因为存在同名文件, 文件名如下:</h3>";    for(int i=0, j=alError.Count; i<j; i++)    {     flMngInfoLabel.Text+="<li/>"+Path.GetFileName(alError[i]+"");    }   }       Session[FileListSession] = null;   SQ.Utility.GoBack("操作完毕, 3 秒后返回, 还有 ", 3,     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);    if(DebugFile)   {    HttpContext.Current.Response.Write("<li/>Move File Method: ");    HttpContext.Current.Response.Write(     "<li/>flMngFileMoveInListRbl.SelectedValue: "+flMngFileMoveInListRbl.SelectedValue);    HttpContext.Current.Response.Write(     "<li/>flMngFileList.Items.Count: "+flMngFileList.Items.Count);   }  }   void FileMoveFileToRootMethod(Object s, EventArgs e)  {      int totalCbx = flMngFileList.Items.Count;      ArrayList alError = new ArrayList();      for(int i=0; i<totalCbx; i++)   {    HtmlInputCheckBox hicb =     (HtmlInputCheckBox)((flMngFileList.Items[i]).FindControl("flMngFileCbx"));        if(hicb.Checked)    {     string finalPath = MapPath(ManageRoot)+Path.GetFileName(hicb.Value);     if(File.Exists(finalPath))     {      alError.Add(finalPath);     }     else     {      File.Move(hicb.Value, finalPath);     }    }   } // end for      if(alError.Count>0)   {    flMngInfoLabel.Text+=     "<h3 class='algc'>有 "+alError.Count+      "个 文件未能移动, 原因为存在同名文件, 文件名如下:</h3>";    for(int i=0, j=alError.Count; i<j; i++)    {     flMngInfoLabel.Text+="<li/>"+Path.GetFileName(alError[i]+"");    }   }       Session[FileListSession] = null;   SQ.Utility.GoBack("操作完毕, 3 秒后返回, 还有 ", 3,     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);  }   void FileMoveFileToParentMethod(Object s, EventArgs e)  {   int totalCbx = flMngFileList.Items.Count;   string rootPath = MapPath(ManageRoot);   ArrayList alError = new ArrayList();      for(int i=0; i<totalCbx; i++)   {    HtmlInputCheckBox hicb =     (HtmlInputCheckBox)((flMngFileList.Items[i]).FindControl("flMngFileCbx"));        if(hicb.Checked)    {     DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(hicb.Value));          string finalPath = di.Parent.FullName+"//"+Path.GetFileName(hicb.Value);          if(finalPath.IndexOf(rootPath)<0)     {      Utility.GoBack("越权, 操作被取消, 3 秒后返回, 还有 ", 3,        HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);      return;     }     if(File.Exists(finalPath))     {      alError.Add(finalPath);     }     else     {      File.Move(hicb.Value, finalPath);     }    }   } // end for      if(alError.Count>0)   {    flMngInfoLabel.Text+=     "<h3 class='algc'>有 "+alError.Count+      "个 文件未能移动, 原因为存在同名文件, 文件名如下:</h3>";    for(int i=0, j=alError.Count; i<j; i++)    {     flMngInfoLabel.Text+="<li/>"+Path.GetFileName(alError[i]+"");    }   }       Session[FileListSession] = null;   SQ.Utility.GoBack("操作完毕, 3 秒后返回, 还有 ", 3,     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);  } </script> <!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> <meta http-equiv="Content-Typecontent="text/html; charset=utf-8" /> <title>shawl.qiu template</title> <style type="text/css"> /*<![CDATA[*/  @import "style/css.css"; /*]]>*/ </style> </head> <body>  <form runat="server">   <!-- Begin flMng -->    <asp:Label id="flMngDebugLabelrunat="server" />    <asp:Label id="flMngNavigatorLabelrunat="server" />    <asp:Label id="flMngInfoLabelrunat="server" />    <asp:PlaceHolder id="flMngPhrunat="server" />      <div class="flMngFolderBar algr">    <asp:PlaceHolder id=flMngFolderPh runat=server     />   </div>    <asp:DataList id="flMngFolderListrunat="server"    BorderColor="black"    CellPadding="5"    CellSpacing="5"    RepeatDirection="Horizontal"    RepeatLayout="Flow"    RepeatColumns="10"    ShowBorder="True"    OnEditCommand="flMngEditCmd"    OnItemCommand="flMngItemCmd"    >     <HeaderTemplate>     <h3>目录:</h3>     <ol class="flMngFolderList">    </HeaderTemplate>        <HeaderStyle >    </HeaderStyle>       <AlternatingItemStyle>    </AlternatingItemStyle>         <ItemTemplate>     <li>      <div class="fltr">       <asp:LinkButton id="flMngEditButtonrunat="server"         Text="Edit"         CommandName="Edit"        />      </div>      <href="?path=<%# DataBinder.Eval(Container.DataItem, "FolderRelativePath") %>">       <%# DataBinder.Eval(Container.DataItem, "FolderName") %>      </a>     </li>     </ItemTemplate>         <EditItemTemplate>     <li>      <href="?path=<%# DataBinder.Eval(Container.DataItem, "FolderRelativePath") %>">       <%# DataBinder.Eval(Container.DataItem, "FolderName") %>      </a>      <ul class="flMngEdit">       <li>        <span onclick="return confirm('确定要重命名文件夹吗?')">         <asp:LinkButton id=flMngUpdateFolderLb runat=server          Text="Rename:"           CommandName="flMngRenameFolderLb"           />         </span>                <asp:TextBox id="flMngUpdateFolderTbxrunat="server"         Text=<%# DataBinder.Eval(Container.DataItem,"FolderName")%>         />                 <input type="hiddenid=flMngUpdateFolderHid runat=server         value=         <%# DataBinder.Eval(Container.DataItem,"FolderRelativePath")%>         />       </li>       <li>        <span onclick="return confirm('现在添加新文件夹吗?')">         <asp:LinkButton id=flMngNewFolderLb runat=server          Text="New Folder:"           CommandName="NewSubFolder"           />         </span>        <asp:TextBox id="flMngNewFolderTbxrunat="server"         />       </li>       <li>         <span onclick="return confirm('确定要删除文件夹吗?')">         <asp:LinkButton id=flMngDeleteFolderLb runat=server          Text="Delete:"           CommandName="flMngDeleteFolder"           />           <%# DataBinder.Eval(Container.DataItem,"FolderRelativePath")%>        </span>       </li>       <li>        <span onclick="return confirm('现在移动文件夹到根目录吗?')">         <asp:LinkButton id=flMngMoveFolderToRootLb runat=server          Text="Move To Root:"           CommandName="MoveFolderToRoot"           />         </span>       </li>       <li>        <span onclick="return confirm('现在移动文件夹到父目录吗?')">         <asp:LinkButton id=flMngMoveFolderToParentLb runat=server          Text="Move To Parent:"           CommandName="MoveFolderToParent"           />         </span>       </li>       <li>        <span onclick="return confirm('现在移动文件夹至选定目录吗?')">         <asp:LinkButton id=flMngMoveFolderInLb runat=server          Text="Move Folder In:"           CommandName="MoveFolderIn"           />         </span>                 <asp:RadioButtonList id="flMngRdoBtnLstrunat="server"         DataValueField="FolderRelativePath"          DataTextField="FolderName"         RepeatDirection="Horizontal"         />       </li>      </ul>     </li>      </EditItemTemplate> <%--    <SeparatorTemplate>     </SeparatorTemplate> --%>    <FooterTemplate>     </ol>    </FooterTemplate>   </asp:DataList>      <div class="flMngUpload">    <asp:PlaceHolder id=flMngUploadPh runat=server />    <asp:PlaceHolder id=flMngEditBoxPh runat=server />   </div>        <div class="flMngFilebar"> <%--    <span onclick="return confirm('确定要移动文件吗?')">     <asp:LinkButton id=flMngMoveFileInLb runat=server      Text="Move File In:"      OnClick="FileMoveFileMethod"      />     </span> --%>    <asp:PlaceHolder id=flMngFileBar runat=server     />    <asp:RadioButtonList id=flMngFileMoveInListRbl runat=server      DataTextField="FolderName"     DataValueField="FolderPhysicalPath"     RepeatDirection="Horizontal"           />   </div>      <asp:DataList id="flMngFileListrunat="server"    BorderColor="black"    CellPadding="5"    CellSpacing="5"    RepeatDirection="Horizontal"    RepeatLayout="Flow"    RepeatColumns="10"    ShowBorder="True"    OnEditCommand="flMngFileEditCmd"    OnItemCommand="flMngFileItemCmd"    >     <HeaderTemplate>     <ol class="flMngFolderList">    </HeaderTemplate>        <HeaderStyle >    </HeaderStyle>       <AlternatingItemStyle>    </AlternatingItemStyle>         <ItemTemplate>     <li>      <div class="fltr">       <asp:LinkButton id="flMngFileEditButton"         Text="Edit"         CommandName="Edit"        runat="server"        />      </div>      <input type="checkboxid="flMngFileCbxrunat="server"        value='<%# DataBinder.Eval(Container.DataItem, "FilePhysicalPath") %>'       />      <href="?id=editfile&filepath=<%# DataBinder.Eval(Container.DataItem, "FileRelativePath") %>">       <%# DataBinder.Eval(Container.DataItem, "FileName") %>      </a>     </li>     </ItemTemplate>    <EditItemTemplate>     <li>      <href="?id=editfile&filepath=<%# DataBinder.Eval(Container.DataItem, "FileRelativePath") %>">       <%# DataBinder.Eval(Container.DataItem, "FileName") %>      </a>      <ul class="flMngEdit">       <li>        <span onclick="return confirm('确定要重命名文件吗?')">         <asp:LinkButton id=flMngRenameFileLb runat=server          Text="Rename:"           CommandName="flMngRenameFile"           />         </span>                <asp:TextBox id="flMngRenameFileTbxrunat="server"         Text=<%# DataBinder.Eval(Container.DataItem,"FileName")%>         />                 <input type="hiddenid=flMngRenameFileHid runat=server         value=         <%# DataBinder.Eval(Container.DataItem,"FileRelativePath")%>         />       </li>       <li>         <span onclick="return confirm('确定要删除文件吗?')">         <asp:LinkButton id=flMngDeleteFileLb runat=server          Text="Delete:"           CommandName="flMngDeleteFile"           />           <%# DataBinder.Eval(Container.DataItem,"FileRelativePath")%>        </span>       </li>       <li>        <span onclick="return confirm('现在移动文件到根目录吗?')">         <asp:LinkButton id=flMngMoveFileToRootLb runat=server          Text="Move To Root:"           CommandName="MoveFileToRoot"           />         </span>       </li>       <li>        <span onclick="return confirm('现在移动文件夹到父目录吗?')">         <asp:LinkButton id=flMngMoveFileToParentLb runat=server          Text="Move To Parent:"           CommandName="MoveFileToParent"           />         </span>       </li>       <li>        <span onclick="return confirm('现在移动文件至选定目录吗?')">         <asp:LinkButton runat=server          Text="Move File In Folder:"           CommandName="MoveFileIn"           />         </span>                 <asp:RadioButtonList id="flMngFileRdoBtnLstrunat="server"         DataValueField="FolderRelativePath"          DataTextField="FolderName"         RepeatDirection="Horizontal"         />       </li>       <li>        <span onclick="return confirm('现在下载文件吗?')">         <asp:LinkButton runat=server          Text="--download file--"           CommandName="DownloadFile"           />         </span>       </li>      </ul>     </li>      </EditItemTemplate> <%--    <SeparatorTemplate>     </SeparatorTemplate> --%>    <FooterTemplate>     </ol>    </FooterTemplate>   </asp:DataList>   <div class="algc"><asp:Label id=flMngFooter runat=server /></div>   <!-- End flMng -->  </form> </body> </html>  

    最新回复(0)