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

来源:互联网 发布:阿里人工智能实验室 编辑:程序博客网 时间:2024/05/18 02:05

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

目录:
1. 简介
2. 核心代码
3. 页面代码

shawl.qiu
2007-02-25
http://blog.csdn.net/btbtd

1. 简介

  1. CREATED BY STABX, AT 2007-2-24.

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

  3. ---/-------------------------------------------------------------

  4. version 1.0

  5. 默认用户名: shawl.qiu 
  6. 默认密码: aaaaaa

  7. 下载:
  8. http://files.myopera.com/btbtd/csharp/class/sq_csharp_FileManager_class_v1.0.7z

  9. 重要提示:
  10. 站点 web.config SessionState 应该设置为 SQLServer 模式, 如下面的设置:
  11. <configuration>
  12.  <!--
  13.  <appSettings>
  14.   <add key="sqvalue="just a test" />
  15.  </appSettings>-->
  16.   <!--Response.Write(ConfigurationSettings.AppSettings["sq"]); -->
  17.  
  18.  <system.web>
  19.   <httpRuntime maxRequestLength="20480"
  20.    useFullyQualifiedRedirectUrl="true"
  21.    executionTimeout="90"
  22.    />
  23.          
  24. <!-- <customErrors defaultRedirect="/include/error/generalError.html"
  25.   mode="RemoteOnly" >
  26.   <error statusCode="404redirect="/include/error/error404.html" />
  27.  </customErrors>-->
  28.  
  29.  <globalization 
  30.   requestEncoding="UTF-8"
  31.   responseEncoding="UTF-8"
  32.   fileEncoding="UTF-8"
  33.   />

  34.  <sessionState mode="SQLServer"
  35.   cookieless="true"
  36.   timeout="20"
  37.   sqlConnectionString="data source=127.0.0.1;user id=sqAspDotNetSession;password=AspDotNetSessionPwd"
  38.   >
  39.  </sessionState>

  40.  </system.web>
  41.  
  42. </configuration>

  43. 或者设置为允许 子目录的 web.config 设置, 在子目录放置上述内容的 web.config

  44. 原因为:
  45. 使用 FileObj.Move() 或 FileInfoObj.MoveTo() 时, 会导致页面重新编译, 从而丢失 Session.
  46. 目前我只找到 Session 的 SQLServer 选项才能解决该问题. 

  47. 功能摘要:
  48.  支持 创建 新文件/新目录
  49.  
  50.  支持编辑文本文件
  51.  
  52.  支持上传文件
  53.  
  54.  支持 移动 文件/目录
  55.  
  56.  支持 删除 文件/目录
  57.  
  58.  支持 重命名 文件/目录
  59.  
  60.  支持 下载文件
  61.  
  62.  支持 验证/不验证(该选项主要为整合程序而设置) 使用权限
  63.  
  64.  支持自定义管理目录
  65.  
  66.  支持编辑用户信息(当选择验证选项时)


  67. 写本程序的动机:
  68.  主要为整合到我的 sqGallery 画廊程序, 
  69.  我想为我的画廊程序 增加文件编辑功能, 
  70.  不过一想可能使代码非常混乱, 
  71.  就打定主意写一个通用性高的文件管理器, 
  72.  唉, 那知道,
  73.  这是一个无底坑, 写了这么一个杂乱无章的文件管理器, 
  74.  不过功能还是挺齐全的.
  75.  
  76.  后续版本主要为 简化/优化 代码.

  77. © 2007-2008, shawl.qiu All rights reserved.

  78. author: shawl.qiu
  79. e-mail: shawl.qiu@gmail.com
  80. blog: http://blog.csdn.net/btbtd
  81. 2007-2-25 0:26:15 


2. 核心代码
  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.IO;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;

  11. public delegate void GeneralEventDelegate(Object s, EventArgs e);

  12. //public delegate void OneArgStringDelegate(String Str);
  13. /*-----------------------------------------------------------------------------------*/
  14.  * shawl.qiu c# .net FileManager class v1.0
  15. /*-----------------------------------------------------------------------------------*/
  16. //---------------------------------------------------------------------begin class FileManager
  17. public class FileManager
  18. {
  19.  //-----------------------------------begin event
  20.  public FileManager()
  21.  {
  22.  }
  23.  
  24.  ~FileManager()
  25.  {
  26.  }
  27.  //-----------------------------------end event
  28.  
  29.  //-----------------------------------begin public constant
  30.  //-----------------------begin about
  31.  public const String auSubject = "shawl.qiu c# .net FileManager class";
  32.  public const String auVersion = "v1.0";
  33.  public const String au = "shawl.qiu";
  34.  public const String auEmail = "shawl.qiu@gmail.com";
  35.  public const String auBlog = "http://blog.csdn.net/btbtd";
  36.  public const String auCreateDate = "2007-2-19";
  37.  //-----------------------end about
  38.  //-----------------------------------end public constant
  39.  
  40.  //-----------------------------------begin public variable
  41.  public bool Debug = false;
  42.  public bool Verify = true;
  43.  
  44.  public string ManageRoot = "/test/";
  45.  public string ProgramRoot = "/sqFlMng/";
  46.  
  47.  public string LoginSession = "sqFlMngLogin";
  48.  public string CheckCodeSession = "sqFlMngCheckCode";
  49.  public string FolderListSession = "flMngVsFolderList";
  50.  public string FileListSession = "flMngVsFileList";
  51.  
  52.  public string LoginGotoUrl = "?";
  53.  public string LogoutGotoUrl = "?";
  54.  
  55.  public string EditableExtension = ".txt|.asp|.aspx|.ascx|.html|.htm|.xml|.xsl|.xslt|.xsd|"+
  56.   ".dtd|s.css|.vbs|.js|.svg|.c|.rss|.wml|.w3d";
  57.  
  58.  public string UploadExtension = "7z,rar,zip,mp3,bmp,gif,jpg,jpeg,png,txt,swf";
  59.  public int UploadTotalKb = 5120;
  60.  public int UploadSingleKb = 1024;
  61.  
  62.  public PlaceHolder MainPlaceHolder;
  63.  public PlaceHolder FolderPlaceHolder;
  64.  public PlaceHolder FilePlaceHolder;
  65.  public PlaceHolder EditBoxPlaceHolder;
  66.  
  67.  public Label NavigatorLabel;
  68.  public Label DebugLabel;
  69.  public Label InfoLabel;
  70.  public Label FooterLabel;
  71.  
  72.  public DataList FolderDataList;
  73.  public DataList FileDataList;
  74.  
  75.  public GeneralEventDelegate MoveFileInFolderDelegate;
  76.  public GeneralEventDelegate MoveFileToRootDelegate;
  77.  public GeneralEventDelegate MoveFileToParentDelegate;
  78.  //-----------------------------------end public variable
  79.  
  80.  //-----------------------------------begin private variable
  81.  private string XmlFilePath = "";
  82.  private string CurrentPath = "";
  83.  private string ManageRoot_Phs = "";
  84.  private string SiteRoot = "";
  85.  
  86.  private string FilePathSession = "flMngFileCurPath";
  87.  private string FolderPathSession = "flMngCurPath";
  88.  //-----------------------------------end private variable
  89.  
  90.  //-----------------------------------begin public method

  91.  public void Go()
  92.  {
  93.   if(MainPlaceHolder==null)return;
  94.   
  95.   if(InfoLabel!=null)InfoLabel.Text="";
  96.   if(DebugLabel!=null)DebugLabel.Text="";
  97.   if(NavigatorLabel!=null)NavigatorLabel.Text="";
  98.   
  99.   if(!ProgramRoot.EndsWith("/")) ProgramRoot+="/";
  100.   XmlFilePath = HttpContext.Current.Server.MapPath(ProgramRoot+"user.xml");
  101.   
  102.   string reqPath = HttpContext.Current.Request.QueryString["path"]+"";
  103.   reqPath = HttpContext.Current.Server.UrlDecode(reqPath);
  104.   if(reqPath==""|reqPath.IndexOf(ManageRoot)!=0)
  105.   {
  106.    CurrentPath = HttpContext.Current.Server.MapPath(ManageRoot);
  107.   }
  108.   else
  109.   {
  110.    CurrentPath = HttpContext.Current.Server.MapPath(reqPath);
  111.   }
  112.   ManageRoot_Phs = HttpContext.Current.Server.MapPath(ManageRoot);
  113.   SiteRoot = HttpContext.Current.Server.MapPath("/");
  114.    
  115.   if(Debug&DebugLabel!=null)
  116.   {
  117.    DebugLabel.Text+="/n<li/>SiteRoot: "+SiteRoot;
  118.    DebugLabel.Text+="/n<li/>ManageRoot_Phs: "+ManageRoot_Phs;
  119.    DebugLabel.Text+="/n<li/>CurrentPath: "+CurrentPath;
  120.    DebugLabel.Text+="/n<hr/>";
  121.   } // end if 1
  122.   
  123.   Navigator(reqPath);
  124.   
  125.   if(Verify)
  126.   {
  127.    bool login = CheckPermission();
  128.    
  129.    if(Debug&DebugLabel!=null)
  130.    {
  131.     DebugLabel.Text+="<li/>LoginSession: "+login;
  132.     DebugLabel.Text+="<hr/>";
  133.    }

  134.    switch(HttpContext.Current.Request.QueryString["id"]+"")
  135.    {
  136.     case "logout":
  137.      HttpContext.Current.Session.Abandon();
  138.      GoBack("已登出系统 ", 3, LogoutGotoUrl, InfoLabel);
  139.      return;
  140.     case "editinfo":
  141.      EditBox(MainPlaceHolder, new EventHandler(EditInfo));
  142.      return;
  143.    }
  144.    
  145.    if(Debug&DebugLabel!=null)
  146.    {
  147.     DebugLabel.Text+="/n<li/>XmlFilePath: "+XmlFilePath;
  148.     DebugLabel.Text+="/n<li/>是否已登陆: "+login;
  149.     DebugLabel.Text+="/n<li/>Session[/"sqFlMngLogin/"]: "+
  150.      HttpContext.Current.Session["sqFlMngLogin"];
  151.     DebugLabel.Text+="/n<hr/>";
  152.    } // end if 1
  153.    
  154.    if(login)
  155.    {
  156.     Main();
  157.    }
  158.    else
  159.    {
  160.     LoginBox(MainPlaceHolder, new EventHandler(CheckLogin));
  161.     return;
  162.    }
  163.   } 
  164.   else
  165.   {
  166.    Main();
  167.   }// end if
  168.   Footer();
  169.  } // end Go;
  170.  //-----------------------------------end public method
  171.  
  172.  //-----------------------------------begin private method
  173.  
  174.  private void EditInfo(Object s, EventArgs e)
  175.  {
  176.   String Username=HttpContext.Current.Request.Form["Username"]+"";
  177.   String Password=HttpContext.Current.Request.Form["Password"]+"";
  178.   String RePassword=HttpContext.Current.Request.Form["RePassword"]+"";
  179.   String CheckCode=HttpContext.Current.Request.Form["CheckCode"]+"";
  180.   String CheckCodeSession=HttpContext.Current.Session["sqFlMngCheckCode"]+"";
  181.   
  182.   if(Debug&&DebugLabel!=null)
  183.   {
  184.    DebugLabel.Text+="<li/>"+Username;
  185.    DebugLabel.Text+="<li/>"+Password;
  186.    DebugLabel.Text+="<li/>"+CheckCode;
  187.    DebugLabel.Text+="<li/>"+CheckCodeSession;
  188.    DebugLabel.Text+="<hr/>";
  189.   }

  190.   if(CheckCode!=CheckCodeSession)
  191.   {
  192.    Message("验证码错误!", InfoLabel);
  193.    goto Error;
  194.   }
  195.  
  196.   if(Username=="")
  197.   {
  198.    Message("用户名不能为空!", InfoLabel);
  199.    goto Error;
  200.   }
  201.   
  202.   Finished:;
  203.   
  204.   string RootPath=HttpContext.Current.Server.MapPath(ProgramRoot);
  205.   if(!RootPath.EndsWith("//"))RootPath+="//";
  206.   
  207.   String FilePath=RootPath+"user.xml";

  208.   DataSet dsDataSet=new DataSet();
  209.   DataTable dtConfig=new DataTable();
  210.   
  211.   dsDataSet.ReadXml(FilePath);
  212.   dtConfig=dsDataSet.Tables["Admin"];
  213.   
  214.   dtConfig.Rows[0]["Username"]=Username;
  215.   
  216.   if(Password!="")
  217.   {
  218.    if(Password!=RePassword)
  219.    {
  220.     Message("密码与确认密码不相同, 操作被终止!", InfoLabel);
  221.     return;
  222.    }
  223.    dtConfig.Rows[0]["Password"]=md5(Password);
  224.   }  
  225.   
  226.   dsDataSet.WriteXml(FilePath);
  227.   
  228.   dsDataSet.Dispose();
  229.   dtConfig.Dispose();
  230.   
  231.   HttpContext.Current.Session.Abandon();
  232.   GoBack("数据已更新, 请重新登陆, 3 秒后返回, 还有 ", 3, "?", InfoLabel);
  233.   
  234.   goto End;
  235.   
  236.   Error:;
  237.   
  238.   goto End;
  239.   
  240.   End:;
  241.  }
  242.  
  243.  private void Message(String word, Label InfoLabel)
  244.  {
  245.   if(InfoLabel==null)return;
  246.   InfoLabel.Text="<div style=/"display:table;width:100%;background-color:yellow!important;"+
  247.     "color:black!important;text-align:center!important;/">"+
  248.     word+"</div>";
  249.  }
  250.  
  251.  private void EditBox(PlaceHolder EditBoxPh, EventHandler SubmitEventHandler)
  252.  {
  253.   if(EditBoxPh==null)goto End;
  254.   
  255.   string RootPath=HttpContext.Current.Server.MapPath(ProgramRoot);
  256.   if(!RootPath.EndsWith("//"))RootPath+="//";
  257.   DataSet dsDataSet=new DataSet();
  258.   DataTable dtConfig=new DataTable();
  259.   
  260.   dsDataSet.ReadXml(RootPath+"user.xml");
  261.   dtConfig=dsDataSet.Tables["Admin"];
  262.   
  263.   
  264.   Literal Br=new Literal();
  265.   Br.Text="<br/>";
  266.   
  267.   Literal Reset=new Literal();
  268.   Reset.Text=
  269.    " <input type=/"reset/" value=/"reset/" onclick=/"return confirm('现在重置吗?');/" />";
  270.   
  271.   Literal ltUsername=new Literal();
  272.   ltUsername.Text="username: ";
  273.  
  274.   TextBox Username=new TextBox();
  275.   Username.ID="Username";
  276.   Username.Text=dtConfig.Rows[0]["Username"]+"";
  277.   
  278.   Literal ltPassword=new Literal();
  279.   ltPassword.Text="<br/>password: ";
  280.  
  281.   TextBox Password=new TextBox();
  282.   Password.ID="Password";
  283.   Password.TextMode=TextBoxMode.Password;
  284.  
  285.   Literal ltRePassword=new Literal();
  286.   ltRePassword.Text="<br/>re-password: ";
  287.   
  288.   TextBox RePassword=new TextBox();
  289.   RePassword.ID="RePassword";
  290.   RePassword.TextMode=TextBoxMode.Password;
  291.   
  292.   Literal ltPublished=new Literal();
  293.   ltPublished.Text="(不更改密码请保留为空)<br/>Published: ";

  294.   Literal ltCheckCode=new Literal();
  295.   ltCheckCode.Text="<br/>CheckCode: ";
  296.   
  297.   TextBox CheckCode=new TextBox();
  298.   CheckCode.ID="CheckCode";
  299.   CheckCode.Columns=4;
  300.   
  301.   Button smtButton=new Button();
  302.   smtButton.ID="glySubmit";
  303.   smtButton.Text="Edit Now";
  304.   smtButton.Click += SubmitEventHandler;
  305.   smtButton.Attributes["onclick"]="javascript:return confirm('请确认更改?')";
  306.   
  307.   System.Web.UI.WebControls.Image CheckCodeImage=new System.Web.UI.WebControls.Image();
  308.   CheckCodeImage.ImageUrl="cs/checkcode.aspx";
  309.   
  310.   EditBoxPh.Controls.Add(ltUsername);  
  311.   EditBoxPh.Controls.Add(Username);
  312.   EditBoxPh.Controls.Add(ltPassword);  
  313.   EditBoxPh.Controls.Add(Password);
  314.   EditBoxPh.Controls.Add(ltRePassword);  
  315.   EditBoxPh.Controls.Add(RePassword);
  316.   EditBoxPh.Controls.Add(ltCheckCode);
  317.   EditBoxPh.Controls.Add(CheckCode);
  318.   EditBoxPh.Controls.Add(CheckCodeImage);
  319.   EditBoxPh.Controls.Add(Br);
  320.   EditBoxPh.Controls.Add(smtButton);
  321.   EditBoxPh.Controls.Add(Reset);
  322.   
  323.   dtConfig.Dispose();
  324.   dsDataSet.Dispose();
  325.   
  326.   End:;
  327.  }
  328.  
  329.  private void Footer()
  330.  {
  331.   if(FooterLabel==null)return;
  332.   
  333.   FooterLabel.Text=auSubject+" "+auVersion+", Powered by "+au+".";
  334.   FooterLabel.Text+="<br/>&copy; 2007-2008, "+au+" All rights reserved.";
  335.  }
  336.  
  337.  private void Main()
  338.  {
  339.   GetFolderBar(FolderPlaceHolder);
  340.   
  341.   switch(HttpContext.Current.Request.QueryString["id"]+"")
  342.   {
  343.    case "upload":
  344.     Upload();
  345.     return;
  346.    case "editfile":
  347.     EditFileBox(EditBoxPlaceHolder);
  348.     return;
  349.   }
  350.   
  351.   ListDirectorys(CurrentPath, ManageRoot_Phs, FolderDataList);
  352.   ListFile(CurrentPath, ManageRoot_Phs, FileDataList);
  353.   GetFileBar(FilePlaceHolder);
  354.  }
  355.  
  356.  private void EditFileBox(PlaceHolder ph)
  357.  {
  358.   if(ph==null)return;
  359.   
  360.   bool Debug =false;
  361.   
  362.   string filePath = HttpContext.Current.Request.QueryString["filePath"]+"";
  363.   string fileName = Path.GetFileName(filePath);
  364.   string fileExt = Path.GetExtension(fileName);
  365.   string finalPath = HttpContext.Current.Server.MapPath(filePath);
  366.   
  367.   if(Debug&DebugLabel!=null)
  368.   {
  369.    DebugLabel.Text += "<li/>Edit File:";
  370.    DebugLabel.Text += "<li/>filePath: "+filePath;
  371.    DebugLabel.Text += "<li/>fileName: "+fileName;
  372.    DebugLabel.Text += "<li/>fileExt: "+fileExt;
  373.    DebugLabel.Text += "<li/>finalPath: "+finalPath;
  374.    DebugLabel.Text += "<li/>CheckPathIn(filePath, ManageRoot, true): "+
  375.     CheckPathIn(filePath, ManageRoot, true);
  376.    DebugLabel.Text += "<li/>CheckExtension(EditableExtension, fileExt): "+
  377.     CheckExtension(EditableExtension, fileExt);
  378.   }
  379.   
  380.   if(filePath=="")
  381.   { 
  382.    GoBack("文件名不能为空, 3 秒后返回, 还有 ", 3, true, InfoLabel);
  383.    return;
  384.   }
  385.   
  386.   if(!CheckPathIn(filePath, ManageRoot, true))
  387.   {
  388.    GoBack("越权, 操作被终止, 3 秒后返回, 还有 ", 3, true, InfoLabel);
  389.    return;
  390.   }
  391.   
  392.   if(fileName.IndexOf(".")<0)
  393.   {
  394.    GoBack("文件名必须有后缀, 3 秒后返回, 还有 ", 3, true, InfoLabel);
  395.    return;
  396.   }
  397.   
  398.   if(!CheckExtension(EditableExtension, fileExt))
  399.   {
  400.    GoBack("不允许编辑的文件类型, 3 秒后返回, 还有 ", 3, true, InfoLabel);
  401.    return;  
  402.   }
  403.   
  404.   if(!File.Exists(finalPath))
  405.   {
  406.    GoBack("文件不存在, 操作被终止, 3 秒后返回, 还有 ", 3, false, InfoLabel);
  407.    return;  
  408.   }
  409.   
  410.   HtmlInputHidden hih = new HtmlInputHidden();
  411.    hih.Value = finalPath;
  412.    hih.ID = "flMngEditFilePath";
  413.   ph.Controls.Add(hih);
  414.    
  415.   Literal ltl;
  416.   
  417.   ltl = new Literal();
  418.   ltl.Text = "<li/>正在编辑文件: <b>"+filePath+"</b><br/>";
  419.   ph.Controls.Add(ltl);
  420.     
  421.   TextBox tbx = new TextBox();
  422.    tbx.TextMode = TextBoxMode.MultiLine;
  423.    tbx.Columns = 60;
  424.    tbx.Rows = 20;
  425.    tbx.Text = ReadTextFile(finalPath);
  426.    tbx.ID = "flMngEditFileContent";
  427.   ph.Controls.Add(tbx);
  428.   
  429.   ltl = new Literal();
  430.   ltl.Text = "<br/>";
  431.   ph.Controls.Add(ltl);
  432.   
  433.   Button btn = new Button();
  434.    btn.Text = "Submit";
  435.    btn.Attributes["onclick"] = "javascript: return confirm('确定更改?')";
  436.    btn.Click += new EventHandler(EditFileChange);
  437.   ph.Controls.Add(btn);
  438.   
  439.   ltl = new Literal();
  440.   ltl.Text = " <input type='reset' value='reset' onclick=/"return confirm('是否重置?');/"";
  441.   ph.Controls.Add(ltl);
  442.   
  443.  } // end private void EditFileBox
  444.  
  445.  private void EditFileChange(Object s, EventArgs e)
  446.  {
  447.   bool Debug=false;
  448.   string finalPath = HttpContext.Current.Request.Form["flMngEditFilePath"]+"";
  449.   string fileContent = HttpContext.Current.Request.Form["flMngEditFileContent"]+"";
  450.   
  451.   if(Debug&InfoLabel!=null)
  452.   {
  453.    InfoLabel.Text+="<li/>finalPath: "+finalPath;
  454.    InfoLabel.Text+="<li/>finalPath: "+fileContent;
  455.   }
  456.   
  457.   WriteTextFile(finalPath, fileContent);
  458.   
  459.   GoBack("文件更新完毕, 3 秒后返回, 还有 ", 3, true, InfoLabel);
  460.   return;  
  461.  }
  462.  
  463.  private void WriteTextFile(string fileName, string content)
  464.  {
  465.   using(StreamWriter sw = new StreamWriter(fileName))
  466.   {
  467.    sw.Write(content);
  468.   }
  469.  } // end private void WriteTextFile
  470.  
  471.  private string ReadTextFile(string filePath)
  472.  {
  473.   if(!File.Exists(filePath))return "false";
  474.   string fileString="";
  475.   using(StreamReader sr = new StreamReader(filePath))
  476.   {
  477.    fileString = sr.ReadToEnd();
  478.   }
  479.   return fileString;
  480.  } // end private string ReadTextFile
  481.  
  482.  private bool CheckExtension(string extList, string extForCheck)
  483.  {
  484.   return Regex.IsMatch(
  485.    extList, 
  486.    @extForCheck.Replace(".","//.")+"//b", 
  487.    RegexOptions.IgnoreCase
  488.    );
  489.  } // end private bool CheckExtension
  490.  
  491.  private bool CheckPathIn(string pathIn, string pathForCheck)
  492.  { 
  493.   if(pathIn.IndexOf(pathForCheck)<0)return false;
  494.   return true;
  495.  }
  496.  
  497.  private bool CheckPathIn(string pathIn, string pathForCheck, bool CovPath)
  498.  {
  499.   if(CovPath)
  500.   {
  501.    pathIn = HttpContext.Current.Server.MapPath(pathIn);
  502.    pathForCheck = HttpContext.Current.Server.MapPath(pathForCheck);
  503.   }
  504.   
  505.   return CheckPathIn(pathIn, pathForCheck);
  506.  }
  507.  
  508.  private void GetFileBar(PlaceHolder ph)
  509.  {
  510.   if(ph==null)return;
  511.   
  512.   Literal ltr = new Literal();
  513.   ltr.Text="<h3>文件操作:</h3>";
  514.   ph.Controls.Add(ltr);
  515.   
  516.   LinkButton lbtn;
  517.   
  518.   lbtn = new LinkButton();
  519.   lbtn.Text = "MoveTo Root | ";
  520.   lbtn.Attributes["onclick"] = "javascript:return confirm('确定要移动文件到根目录吗?');";
  521.   if(MoveFileToRootDelegate!=null)
  522.   lbtn.Click+=new EventHandler(MoveFileToRootDelegate);
  523.   ph.Controls.Add(lbtn);
  524.   
  525.   lbtn = new LinkButton();
  526.   lbtn.Text = "MoveTo Parent | ";
  527.   lbtn.Attributes["onclick"] = "javascript:return confirm('确定要移动文件到父目录吗?');";
  528.   if(MoveFileToParentDelegate!=null)
  529.   lbtn.Click+=new EventHandler(MoveFileToParentDelegate);
  530.   ph.Controls.Add(lbtn);
  531.   
  532.   lbtn = new LinkButton();
  533.   lbtn.Text = "Move File In: ";
  534.   lbtn.Attributes["onclick"] = "javascript:return confirm('确定要移动文件吗?');";
  535.   if(MoveFileInFolderDelegate!=null)
  536.   lbtn.Click+=new EventHandler(MoveFileInFolderDelegate);
  537.   ph.Controls.Add(lbtn);
  538.   
  539.  }
  540.  
  541.  private void GetFolderBar(PlaceHolder ph)
  542.  {
  543.   if(ph==null)return;
  544.   Literal ltl;
  545.   
  546.   LinkButton lbtn = new LinkButton();
  547.   lbtn.Text="New Directory";
  548.   lbtn.Click += new EventHandler(CreateNewDirectory);
  549.   lbtn.Attributes["onclick"] = "return confirm('现在创建新文件夹吗?')";
  550.   ph.Controls.Add(lbtn);
  551.   
  552.   ltl = new Literal();
  553.   ltl.Text=" | ";
  554.   ph.Controls.Add(ltl);
  555.   
  556.   LinkButton lbtnNewFile = new LinkButton();
  557.   lbtnNewFile.Text="New File(txtfile)";
  558.   lbtnNewFile.Click += new EventHandler(CreateNewFile);
  559.   lbtnNewFile.Attributes["onclick"] = "return confirm('现在创建新文件吗?')";
  560.   ph.Controls.Add(lbtnNewFile);
  561.   
  562.   ltl = new Literal();
  563.   ltl.Text=": ";
  564.   ph.Controls.Add(ltl);
  565.   
  566.   TextBox tbx = new TextBox();
  567.   tbx.ID = "flMngCreateNewFolderInCurrent";
  568.   ph.Controls.Add(tbx);
  569.   
  570.   string QueryUrl="";
  571.   AutoConvertPagedUrl("id", out QueryUrl); 
  572.   ltl = new Literal();
  573.   ltl.Text = " <a href='"+QueryUrl+"upload'>upload</a>";
  574.   
  575.   ph.Controls.Add(ltl);
  576.  }
  577.  
  578.  private void ListFile(string path, string pathForCheck, DataList dl)
  579.  {
  580.   if(path.IndexOf(pathForCheck)<0|dl==null)return;
  581.   
  582.   DirectoryInfo di = new DirectoryInfo(path);
  583.   FileInfo[] fiArray = di.GetFiles();
  584.   
  585.   int TotalFile = fiArray.Length;
  586.   
  587.   if(TotalFile==0)
  588.   {
  589.    InfoLabel.Text+="<h2 class='algc'>当前目录没有文件.</h2>";
  590.    HttpContext.Current.Session[FileListSession] = null;
  591.    return;
  592.   }
  593.   
  594.   if(Debug&DebugLabel!=null)
  595.   {
  596.    DebugLabel.Text+="<li/>TotalFiles: "+TotalFile;
  597.     
  598.    DebugLabel.Text+="<hr/>";
  599.   }
  600.   
  601.   if(HttpContext.Current.Session[FileListSession]==null|
  602.    HttpContext.Current.Session[FilePathSession]+""!=path)
  603.   {   
  604.    DataTable dt = new DataTable();
  605.    DataRow dr;
  606.    
  607.    CreateDataColumn(dt, "FileName", typeof(string));
  608.    CreateDataColumn(dt, "FileRelativePath", typeof(string));
  609.    CreateDataColumn(dt, "FilePhysicalPath", typeof(string));
  610.    
  611.    for(int i=0, j=fiArray.Length; i<j; i++)
  612.    {
  613.     string FilePath = fiArray[i].FullName+"";
  614.     ConvertPathToRelative(ref FilePath);;
  615.     
  616.     dr = dt.NewRow();
  617.     dr[0]=fiArray[i].Name;
  618.     dr[1]=FilePath;
  619.     dr[2]=fiArray[i].FullName;
  620.     dt.Rows.Add(dr);
  621.    }
  622.    dl.DataSource = dt.DefaultView;
  623.    dl.DataBind();
  624.    HttpContext.Current.Session[FileListSession] = dt;
  625.    HttpContext.Current.Session[FilePathSession] = path;
  626.   }
  627.   else 
  628.   {
  629.    HttpContext.Current.Session[FilePathSession] = path;
  630.   }
  631.  } // end private void ListFile
  632.  
  633.  private void ListDirectorys(string path, string pathForCheck, DataList dl)
  634.  { 
  635.   if(path.IndexOf(pathForCheck)<0|dl==null)return;
  636.   
  637.   if(HttpContext.Current.Session[FolderListSession]==null|
  638.    HttpContext.Current.Session[FolderPathSession]+""!=path)
  639.   {
  640.    if(Debug&DebugLabel!=null)
  641.    {
  642.     DebugLabel.Text+="<li/>Session[/"FolderPathSession/"]: "+
  643.      HttpContext.Current.Session[FolderPathSession];
  644.      
  645.     DebugLabel.Text+="<hr/>";
  646.    }
  647.    
  648.    DirectoryInfo di = new DirectoryInfo(path);
  649.    DirectoryInfo[] diArray = di.GetDirectories();
  650.    
  651.    if(diArray.Length==0)
  652.    {
  653.     InfoLabel.Text+="<h2 class='algc'>当前目录没有子目录.</h2>";
  654.     HttpContext.Current.Session[FolderListSession] = null;
  655.     //return;
  656.    }
  657.    
  658.    DataTable dt = new DataTable();
  659.    DataRow dr;
  660.    
  661.    CreateDataColumn(dt, "FolderName", typeof(string));
  662.    CreateDataColumn(dt, "FolderRelativePath", typeof(string));
  663.    CreateDataColumn(dt, "FolderPhysicalPath", typeof(string));
  664.    
  665.    for(int i=0, j=diArray.Length; i<j; i++)
  666.    {
  667.     string FolderPath = diArray[i].FullName+"";
  668.     ConvertPathToRelative(ref FolderPath, true);
  669.     
  670.     dr = dt.NewRow();
  671.     dr[0]=diArray[i].Name;
  672.     dr[1]=FolderPath;
  673.     dr[2]=diArray[i].FullName;
  674.     dt.Rows.Add(dr);
  675.    }
  676.    dl.DataSource = dt.DefaultView;
  677.    dl.DataBind();
  678.    HttpContext.Current.Session[FolderListSession] = dt;
  679.    HttpContext.Current.Session[FolderPathSession] = path;
  680.   }
  681.   else 
  682.   {
  683.    HttpContext.Current.Session[FolderPathSession] = path;
  684.   }
  685.  }
  686.  
  687.  private void Upload()
  688.  {
  689.   if(EditBoxPlaceHolder==null)return;
  690.   string QueryUrl="";
  691.   AutoConvertPagedUrl("id", out QueryUrl); 
  692.   string uploadPath = HttpContext.Current.Request.QueryString["path"]+"";
  693.   if(uploadPath=="")uploadPath = ManageRoot;

  694.   upload up=new upload();
  695.   up.ext=UploadExtension;
  696.   up.debug=false;
  697.   up.item=5;                      // 声明显示多少个上传框
  698.   up.path=uploadPath;            // 上传目录;
  699.   up.goback_url=QueryUrl+"upload";   // 上传完毕后返回的 URL
  700.   up.goback_second=5;             // 上传后返回间隔
  701.   up.interval=5;                  // 每次上传间隔, 单位秒
  702.   up.autorename=true;             // 自动重命名;
  703.   
  704.   up.totalsize = UploadTotalKb;
  705.   up.singlesize = UploadSingleKb;
  706.   
  707.   // 声明 处理 所有 返回路径 的方法
  708.   //up.ReturnFilePath=new OneArgStringDelegate(GetPath);
  709.   
  710.   up.UploadPh=EditBoxPlaceHolder;           // 声明显示上传控件的占位符
  711.   up.UploadBox();                 // 显示上传操作控件
  712.   
  713.   up=null;
  714.  }
  715.  
  716.  private void AutoConvertPagedUrl(String QueryId, out String QueryUrl)
  717.  {
  718.   QueryUrl=System.Web.HttpContext.Current.Request.Url+"";
  719.   
  720.   if(QueryUrl.IndexOf(@"?")==-1)
  721.   {
  722.    QueryUrl+=@"?";
  723.   }
  724.   QueryUrl=Regex.Replace(QueryUrl,@"/b"+@QueryId+@"/=[^&]+","", RegexOptions.IgnoreCase);
  725.   QueryUrl+="&"+QueryId+"=";
  726.   QueryUrl=Regex.Replace(QueryUrl,@"/?/&",@"?", RegexOptions.IgnoreCase);
  727.   QueryUrl=Regex.Replace(QueryUrl,@"/&+",@"&", RegexOptions.IgnoreCase);
  728.   
  729.   string sReferrer = System.Web.HttpContext.Current.Request.UrlReferrer+"";
  730.   if(sReferrer.IndexOf("(")>-1&&sReferrer.IndexOf(")")>-1)
  731.   {
  732.    sReferrer = Regex.Replace(sReferrer, @".*(/(.*/)).*", "$1");
  733.    QueryUrl = Regex.Replace(
  734.     QueryUrl, @"(http/:////.*?//)", "$1"+sReferrer+"/", RegexOptions.IgnoreCase);
  735.   }
  736.  } // end private void AutoConvertPagedUrl
  737.  //-----------------------------------end private method
  738.  
  739.  private void CreateNewFile(Object s, EventArgs e)
  740.  {
  741.   Control ctlPh = FolderPlaceHolder.FindControl("flMngCreateNewFolderInCurrent");
  742.   if(ctlPh!=null)
  743.   {
  744.    TextBox tbx = (TextBox)ctlPh;
  745.    if(tbx.Text!="")
  746.    {
  747.     string finalFileName = CurrentPath+tbx.Text;
  748.     
  749.     if(Debug&DebugLabel!=null)
  750.     {
  751.      DebugLabel.Text+="<li/>new file string:"+tbx.Text;
  752.      DebugLabel.Text+="<li/>finalFileName:"+finalFileName;
  753.      
  754.      DebugLabel.Text+="<hr/>";
  755.     }
  756.     
  757.     if(tbx.Text.IndexOf(".")<0)
  758.     {
  759.      GoBack("新文件必须有扩展名, 操作被取消, 3 秒反返回, 还有 ", 3, 
  760.       HttpContext.Current.Request.UrlReferrer+"", InfoLabel);
  761.       return;
  762.     }
  763.     
  764.     if(File.Exists(finalFileName))
  765.     {
  766.      GoBack("文件已存在, 操作被取消, 3 秒反返回, 还有 ", 3, 
  767.       HttpContext.Current.Request.UrlReferrer+"", InfoLabel);
  768.       return;
  769.     }
  770.     else
  771.     {
  772.      using(StreamWriter sw = new StreamWriter(finalFileName))
  773.      {
  774.      
  775.      }
  776.      HttpContext.Current.Session[FileListSession] = null;
  777.      GoBack("新文件已创建, 3 秒反返回, 还有 ", 3, 
  778.       HttpContext.Current.Request.UrlReferrer+"", InfoLabel);
  779.       return;
  780.     }
  781.    }
  782.   }
  783.  }
  784.  
  785.  private void CreateNewDirectory(Object s, EventArgs e)
  786.  {
  787.   Control ctlPh = FolderPlaceHolder.FindControl("flMngCreateNewFolderInCurrent");
  788.   if(ctlPh!=null)
  789.   {
  790.    TextBox tbx = (TextBox)ctlPh;
  791.    if(tbx.Text!="")
  792.    {
  793.     string newFolder = CurrentPath+tbx.Text;
  794.     if(!Directory.Exists(newFolder))
  795.     {
  796.      Directory.CreateDirectory(newFolder);
  797.      HttpContext.Current.Session[FolderListSession] = null;
  798.      GoBack("新文件夹已创建, 3 秒反返回, 还有 ", 3, 
  799.       HttpContext.Current.Request.UrlReferrer+"", InfoLabel);
  800.       return;
  801.     }
  802.     else
  803.     {
  804.      GoBack("文件夹已存在, 操作被取消, 3 秒反返回, 还有 ", 3, 
  805.       HttpContext.Current.Request.UrlReferrer+"", InfoLabel);
  806.       return;
  807.     }
  808.    }
  809.   }
  810.  }
  811.  
  812.  private StringBuilder GetPath(String PathQuery, String LinkString)
  813.  {
  814.   PathQuery=System.Web.HttpContext.Current.Server.UrlDecode(PathQuery);
  815.   if(!PathQuery.EndsWith("/"))PathQuery+="/";
  816.   StringBuilder sb=new StringBuilder();
  817.   String[] PathTemp=PathQuery.Split('/');
  818.   for(Int32 i=0, j=PathTemp.Length; i<j; i++)
  819.   {
  820.    if(PathTemp[i]!="")
  821.    {
  822.     sb.Append(" -> ");
  823.     if(i==j-2)
  824.     {
  825.      sb.Append("[");
  826.     }
  827.     sb.Append("<a href=/""+LinkString);
  828.     sb.Append("/");
  829.     for(Int32 k=0; k<=i; k++)
  830.     {  
  831.      if(PathTemp[k]!="")
  832.      {
  833.       sb.Append(System.Web.HttpContext.Current.Server.UrlEncode(PathTemp[k]));
  834.       sb.Append("/");
  835.      }
  836.     }
  837.     sb.Append("/">");
  838.     sb.Append(PathTemp[i]);
  839.     sb.Append("</a>");
  840.     if(i==j-2)
  841.     {
  842.      sb.Append("]");
  843.     }
  844.    }
  845.   }
  846.   return sb;
  847.  } // end private StringBuilder GetPath 
  848.  
  849.  protected void CreateDataColumn(DataTable dt, String fieldName, Type tp)
  850.  {
  851.   dt.Columns.Add(new DataColumn(fieldName, tp));
  852.  }
  853.  
  854.  protected void CreateDataColumn(DataTable dt, String fieldName)
  855.  {
  856.   dt.Columns.Add(new DataColumn(fieldName, typeof(int)));
  857.  } 
  858.  
  859.  private void ConvertPathToRelative(ref string FolderPath)
  860.  {
  861.   string SiteRoot= HttpContext.Current.Server.MapPath("/");
  862.   
  863.   FolderPath = FolderPath.Replace(SiteRoot, "").Replace(@"/", "/");
  864.   if(!FolderPath.StartsWith("//"))FolderPath="/"+FolderPath;
  865.   FolderPath = HttpContext.Current.Server.UrlPathEncode(FolderPath);
  866.  } 
  867.  
  868.  private void ConvertPathToRelative(ref string FolderPath, bool plusSlash)
  869.  {
  870.   ConvertPathToRelative(ref FolderPath);
  871.   
  872.   if(plusSlash)
  873.   if(!FolderPath.EndsWith("//"))FolderPath+="/";
  874.  }
  875.  
  876.  private void Navigator(string curPath)
  877.  {
  878.   if(NavigatorLabel==null)return;
  879.   
  880.   if(Debug&DebugLabel!=null)
  881.   {
  882.    DebugLabel.Text+="/n<li/>NavigatorLable ok. ";
  883.    DebugLabel.Text+="/n<hr/>";
  884.   }
  885.   
  886.   NavigatorLabel.Text+="/n<div class='algr flMngNavigator'>/n";
  887.   
  888.   bool login = CheckPermission();
  889.   
  890.   if(!Verify|login)
  891.   { 
  892.    bool mode=false;
  893.    if(login) mode=true;
  894.     
  895.    NavigatorMethod(curPath, mode);
  896.   }
  897.   
  898.   NavigatorLabel.Text+="/n</div>";
  899.  } // end public void Navigator
  900.  
  901.  private void NavigatorMethod(string curPath, bool loginMode)
  902.  {
  903.   NavigatorLabel.Text+=
  904.    "<div class='fltl algl'>"+
  905.    "<a href='?path="+ManageRoot+"'>sqFlMng Root</a> "+
  906.    GetPath(curPath, "?path=")+
  907.    "</div>&nbsp";
  908.    
  909.   if(loginMode)
  910.   {
  911.    NavigatorLabel.Text+=" <a href='?id=editinfo'>EditInfo</a>";
  912.    NavigatorLabel.Text+=" <a href='?id=logout'>logout</a>";
  913.   }
  914.  }
  915.  
  916.  private bool CheckPermission()
  917.  {
  918.   DataTable dt = ReadDataSetTable(XmlFilePath, "Admin"); 
  919.   if(dt==null)
  920.    return false;
  921.    
  922.    string login = HttpContext.Current.Session[LoginSession]+"";
  923.    
  924.    if(login=="") return false;
  925.    return true;
  926.  } // end private bool CheckPermission
  927.  
  928.  private DataTable ReadDataSetTable(string filePath, string tableName)
  929.  {
  930.   DataSet ds = new DataSet();
  931.    ds.ReadXml(filePath);
  932.   return ds.Tables[tableName];
  933.  } // end private DataTable ReadDataSetTable
  934.  
  935.  private void LoginBox(PlaceHolder EditBoxPh, EventHandler SubmitEventHandler)
  936.  {
  937.   if(EditBoxPh==null)goto End;
  938.   
  939.   Literal Br=new Literal();
  940.   Br.Text="<br/>";
  941.   
  942.   Literal ltUsername=new Literal();
  943.   ltUsername.Text="Username: ";
  944.   
  945.   Literal ltPassword=new Literal();
  946.   ltPassword.Text="<br/>Password: ";
  947.   
  948.   Literal ltCheckCode=new Literal();
  949.   ltCheckCode.Text="<br/>CheckCode: ";
  950.   
  951.   TextBox Username=new TextBox();
  952.   Username.ID="Username";
  953.   
  954.   TextBox CheckCode=new TextBox();
  955.   CheckCode.ID="CheckCode";
  956.   CheckCode.Columns=4;
  957.   
  958.   TextBox Password=new TextBox();
  959.   Password.TextMode=TextBoxMode.Password;
  960.   Password.ID="Password";
  961.   
  962.   Button smtButton=new Button();
  963.   smtButton.ID="glySubmit";
  964.   smtButton.Text="login now";
  965.   smtButton.Click += SubmitEventHandler;
  966.   smtButton.Attributes["onclick"]="javascript:return confirm('现在登陆吗?')";
  967.   
  968.   Literal Reset=new Literal();
  969.   Reset.Text=" <input type=/"reset/" value=/"reset/" "+
  970.    "onclick=/"return confirm('现在重置吗');/" />";
  971.   
  972.   System.Web.UI.WebControls.Image CheckCodeImage=new System.Web.UI.WebControls.Image();
  973.   CheckCodeImage.ImageUrl="cs/checkcode.aspx";
  974.   
  975.   EditBoxPh.Controls.Add(ltUsername);
  976.   EditBoxPh.Controls.Add(Username);
  977.   EditBoxPh.Controls.Add(ltPassword);
  978.   EditBoxPh.Controls.Add(Password);
  979.   EditBoxPh.Controls.Add(ltCheckCode);
  980.   EditBoxPh.Controls.Add(CheckCode);
  981.   EditBoxPh.Controls.Add(CheckCodeImage);
  982.   EditBoxPh.Controls.Add(Br);
  983.   EditBoxPh.Controls.Add(smtButton);
  984.   EditBoxPh.Controls.Add(Reset);
  985.   
  986.   End:;
  987.  }
  988.  
  989.  private void CheckLogin(Object s, EventArgs e)
  990.  {
  991.  String Username=HttpContext.Current.Request.Form["Username"]+"";
  992.  String Password=HttpContext.Current.Request.Form["Password"]+"";
  993.   Password=md5(Password);
  994.  String CheckCode=HttpContext.Current.Request.Form["CheckCode"]+"";
  995.  String CheckCodeSession_=HttpContext.Current.Session[CheckCodeSession]+"";
  996.  
  997.  if(CheckCode!=CheckCodeSession_)
  998.  {
  999.   GoBack("验证码不正确, 3秒后返回, 还有 ", 3, 
  1000.    HttpContext.Current.Request.Url+"", InfoLabel);
  1001.   goto Error;
  1002.  }
  1003.  
  1004.   string RootPath=HttpContext.Current.Server.MapPath(ProgramRoot);
  1005.   if(!RootPath.EndsWith("//"))
  1006.   { 
  1007.    RootPath+="//";
  1008.   }
  1009.   DataSet dsDataSet=new DataSet();
  1010.   DataTable dtConfig=new DataTable();
  1011.  
  1012.   dsDataSet.ReadXml(XmlFilePath);
  1013.   dtConfig=dsDataSet.Tables["Admin"];
  1014.   
  1015.   DataRow[] drArray;
  1016.    
  1017.    drArray = dtConfig.Select("Username = '"+Username+"'");
  1018.   
  1019.   if(drArray.Length==0)
  1020.   {
  1021.    GoBack("用户名错误, 3秒后返回, 还有 ", 3, 
  1022.     HttpContext.Current.Request.Url+"", InfoLabel);
  1023.    return;
  1024.   }
  1025.   
  1026.    drArray = dtConfig.Select("Username = '"+Username
  1027.     +"' and Password = '"+Password+"'");
  1028.     
  1029.   if(drArray.Length==0)
  1030.   {
  1031.    GoBack("密码错误, 3秒后返回, 还有 ", 3, 
  1032.     HttpContext.Current.Request.Url+"", InfoLabel);
  1033.     return;
  1034.   }
  1035.   
  1036.   HttpContext.Current.Session[LoginSession]="ok";
  1037.   GoBack("登陆成功, 3秒后返回, 还有 ", 3, "?", InfoLabel);
  1038.   return;
  1039.   
  1040.   Error:;
  1041.   End:;
  1042.  }
  1043.  
  1044.  private void GoBack(String sPrompt, Int32 iSecond, String sUrl, Label GobackLabel)
  1045.  {
  1046.   if(GobackLabel==nullreturn;
  1047.   GobackLabel.Text+="<script type=/"text/javascript/">/n";
  1048.   GobackLabel.Text+="//<![CDATA[/n";
  1049.   GobackLabel.Text+=var temp=onload;/n";
  1050.   GobackLabel.Text+=onload=function(){/n";
  1051.   GobackLabel.Text+="  try{temp()}catch(e){}/n";
  1052.   GobackLabel.Text+="  fTimer("+iSecond+",'timer', 10);/n";
  1053.   GobackLabel.Text+=" }/n";
  1054.   GobackLabel.Text+="  function fTimer(iTimestamp, sId, iMs){/n";
  1055.   GobackLabel.Text+="  if(!(iTimestamp.constructor==Date)){/n";
  1056.   GobackLabel.Text+="   var sqTimeStamp=new Date();/n";
  1057.   GobackLabel.Text+="   sqTimeStamp.setSeconds(sqTimeStamp.getSeconds()+iTimestamp);/n";
  1058.   GobackLabel.Text+="   iTimestamp=sqTimeStamp;/n";
  1059.   GobackLabel.Text+="  }/n";
  1060.   GobackLabel.Text+="    var tl=arguments.callee;/n";
  1061.   GobackLabel.Text+="    if(typeof sId=='string'){/n";
  1062.   GobackLabel.Text+="   var oEle=document.getElementById(sId);/n";
  1063.   GobackLabel.Text+="  } else {/n";
  1064.   GobackLabel.Text+="   var oEle=sId;/n";
  1065.   GobackLabel.Text+="  }/n";
  1066.   GobackLabel.Text+="  var dt=new Date();/n";
  1067.   GobackLabel.Text+="  var iCk=((iTimestamp.getTime()-dt.getTime())/1000).toFixed(3);/n";
  1068.   GobackLabel.Text+="  if(iCk<=0){/n";
  1069.   GobackLabel.Text+="   oEle.innerHTML='00.000';/n";
  1070.   GobackLabel.Text+="   return false;/n";
  1071.   GobackLabel.Text+="  } else {/n";
  1072.   GobackLabel.Text+="   oEle.innerHTML=iCk;/n";
  1073.   GobackLabel.Text+="   var iTimer=setTimeout(function(){tl(iTimestamp, oEle, iMs)},iMs); /n";
  1074.   GobackLabel.Text+="  }/n";
  1075.   GobackLabel.Text+=" } // end function fTimer // shawl.qiu script/n";
  1076.   GobackLabel.Text+="//]]>/n";
  1077.   GobackLabel.Text+="</script>/n";

  1078.   GobackLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset=utf-8/" />";
  1079.   GobackLabel.Text+="<meta http-equiv=/"refresh/" content=/""+iSecond+";URL="+sUrl+"/">";
  1080.   GobackLabel.Text+="<div style=/"display:table;width:100%;background-color:yellow!important;"+
  1081.     "color:black!important;text-align:center!important;/">"+
  1082.     sPrompt+", <span id='timer'>"+iSecond+"</span>秒 后返回.</div>";
  1083.  }
  1084.  
  1085.  private void GoBack(String sPrompt, Int32 iSecond, bool byReferrer, Label GobackLabel)
  1086.  {
  1087.   if(GobackLabel==null)return;
  1088.   string url = "?";
  1089.   if(byReferrer) url = HttpContext.Current.Request.UrlReferrer+"";
  1090.   GoBack(sPrompt, iSecond, url, GobackLabel);
  1091.  }
  1092.  
  1093.  private String md5(String sMd5)
  1094.  {
  1095.   return System.Web.Security.FormsAuthentication.
  1096.    HashPasswordForStoringInConfigFile(sMd5, "MD5");
  1097.  }
  1098. }
  1099. //---------------------------------------------------------------------end class FileManager 

3. 页面代码
  1. <%@ Page Language="C#AutoEventWireup="True" %>
  2. <%@ import Namespace="System.Data" %>
  3. <%@ import Namespace="System.Collections" %>
  4. <%@ import Namespace="System.IO" %>
  5. <%@ import Namespace="System.Text.RegularExpressions" %>
  6. <%@ import Namespace="System.Web.UI.HtmlControls" %>
  7. <%@ Assembly src="cs/FileManager.cs" %>
  8. <%@ Assembly src="cs/sqNS.cs" %>
  9. <%@ import Namespace="SQ" %>
  10. <script runat="server">

  11.  /* Start flMng Global setting */
  12.   public bool Debug = false;
  13.   
  14.   public bool DebugFile = false;
  15.   
  16.   public string ManageRoot="/test/";
  17.   
  18.   public string LoginSession = "sqFlMngLogin"; 
  19.   public string FolderListSession = "flMngVsFolderList";
  20.   public string FileListSession = "flMngVsFileList";
  21.   
  22.  /* End flMng Global setting */

  23.  void Page_Load(Object s, EventArgs e)
  24.  {
  25.   FileManager flMng = new FileManager();
  26.   
  27.    flMng.Debug = Debug;                 // 是否为调试模式
  28.     
  29.    flMng.Verify = true;                // 是否起用验证
  30.    flMng.LoginSession = LoginSession;// 声明验证是否登陆的 Session 项(不为空则认为已登陆)
  31.    flMng.FolderListSession = FolderListSession;
  32.    flMng.FileListSession = FileListSession;
  33.    
  34.    flMng.ManageRoot = ManageRoot;        // 要管理的文件目录
  35.    flMng.ProgramRoot = "/sqFlMng/";    // 本程序所在目录
  36.    
  37.    flMng.LoginGotoUrl = "?";
  38.    flMng.LogoutGotoUrl = "?";
  39.    
  40.    flMng.UploadExtension = "7z,rar,zip,mp3,bmp,gif,jpg,jpeg,png,txt,swf";
  41.    flMng.UploadTotalKb = 5120;
  42.    flMng.UploadSingleKb = 1024;
  43.    
  44.    flMng.EditableExtension = ".txt|.asp|.aspx|.ascx|.html|.htm|.xml|.xsl|.xslt|.xsd|.dtd|"+
  45.    ".css|.vbs|.js|.svg|.c|.rss|.wml|.w3d"; 

  46.    flMng.DebugLabel = flMngDebugLabel;
  47.    flMng.NavigatorLabel = flMngNavigatorLabel;
  48.    flMng.InfoLabel = flMngInfoLabel;
  49.    flMng.FooterLabel = flMngFooter;
  50.    
  51.    flMng.MainPlaceHolder = flMngPh;
  52.    
  53.    flMng.FolderPlaceHolder = flMngFolderPh;
  54.    flMng.FilePlaceHolder = flMngFileBar;
  55.    
  56.    flMng.EditBoxPlaceHolder = flMngEditBoxPh;
  57.    
  58.    flMng.FolderDataList = flMngFolderList;
  59.    flMng.FileDataList = flMngFileList;
  60.    
  61.    flMng.MoveFileInFolderDelegate = new GeneralEventDelegate(FileMoveFileMethod);
  62.    flMng.MoveFileToRootDelegate = new GeneralEventDelegate(FileMoveFileToRootMethod);
  63.    flMng.MoveFileToParentDelegate = new GeneralEventDelegate(FileMoveFileToParentMethod);
  64.       
  65.    flMng.Go();
  66.   
  67.   flMng=null
  68.   
  69.   string QueryId = Request.QueryString["id"]+"";
  70.   
  71.   switch(QueryId)
  72.   {
  73.    case "editinfo":break;
  74.    case "editfile":break;
  75.    default:
  76.     if (!IsPostBack)
  77.     {
  78.      BindList(flMngFolderList, FolderListSession);
  79.      BindList(flMngFileList, FileListSession);
  80.      
  81.      flMngFileMoveInListRbl.DataSource = (DataTable)Session[FolderListSession];
  82.      flMngFileMoveInListRbl.DataBind();
  83.     }
  84.     break;
  85.   }
  86.  } // end Page_Load
  87.  
  88.  void BindList(DataList dl, string sessionName) 
  89.  {
  90.   dl.DataSource = (DataTable)Session[sessionName];
  91.   dl.DataBind();
  92.  }
  93.  
  94.  void flMngEditCmd(Object sender, DataListCommandEventArgs e) 
  95.  {
  96.   DataList dl = (DataList)sender;
  97.   dl.EditItemIndex = e.Item.ItemIndex;
  98.   BindList(dl, FolderListSession);  
  99.   
  100.   string sForDelete = 
  101.    ((HtmlInputHidden)(dl.Items[e.Item.ItemIndex].FindControl("flMngUpdateFolderHid"))).Value;
  102.   
  103.   RadioButtonList rbl =
  104.    (RadioButtonList)(dl.Items[e.Item.ItemIndex].FindControl("flMngRdoBtnLst"));
  105.    
  106.   DataTable dt = ((DataTable)Session[FolderListSession]).Copy();
  107.   
  108.   DeleteTableRow(dt, "FolderRelativePath = '"+sForDelete+"'");
  109.    
  110.   rbl.DataSource = dt;
  111.   rbl.DataBind();
  112.  }
  113.  
  114.  void flMngFileEditCmd(Object sender, DataListCommandEventArgs e) 
  115.  {
  116.   DataList dl = (DataList)sender;
  117.   dl.EditItemIndex = e.Item.ItemIndex;
  118.   BindList(dl, FileListSession); 
  119.   
  120.   RadioButtonList rbl =
  121.    (RadioButtonList)(dl.Items[e.Item.ItemIndex].FindControl("flMngFileRdoBtnLst"));
  122.    
  123.   DataTable dt = ((DataTable)Session[FolderListSession]).Copy();
  124.   rbl.DataSource = dt;
  125.   rbl.DataBind();
  126.  }
  127.  
  128.  private void DeleteTableRow(DataTable dt, string condition)
  129.  {
  130.   DataRow[] drArray = dt.Select(condition);
  131.   
  132.   for(int i = 0; i< drArray.Length; i++)
  133.   {
  134.    drArray[i].Delete();
  135.   }
  136.  } // end private void DeleteTableRow
  137.  
  138.  void flMngRenameFolderCmd(Object sender, DataListCommandEventArgs e) 
  139.  { 
  140.   string updateString = ((TextBox)e.Item.FindControl("flMngUpdateFolderTbx")).Text;
  141.   updateString = Regex.Replace(updateString, @"^/s+|/s+$", "");
  142.   
  143.   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;
  144.   folderString=HttpContext.Current.Server.UrlDecode(folderString);
  145.   
  146.   
  147.   if(updateString!="")
  148.   {
  149.    DirectoryInfo di = new DirectoryInfo(MapPath(folderString));
  150.    
  151.    string destination = di.Parent.FullName+@"/"+updateString+@"/";
  152.    
  153.    if(!Directory.Exists(destination))
  154.    {
  155.     di.MoveTo(destination)
  156.     Session[FolderListSession] = null;
  157.      
  158.     Utility.GoBack("文件夹已重命名, 3 秒后返回, 还有 ", 3, 
  159.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  160.     return;
  161.    }
  162.    else
  163.    {
  164.     Utility.GoBack("已存在相同的文件夹, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  165.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  166.    }
  167.   } 
  168.  } // end void flMngUpdateFolderCmd
  169.  
  170.  void flMngRenameFileCmd(Object sender, DataListCommandEventArgs e) 
  171.  { 
  172.   string updateString = ((TextBox)e.Item.FindControl("flMngRenameFileTbx")).Text;
  173.   updateString = Regex.Replace(updateString, @"^/s+|/s+$", "");
  174.   
  175.   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;
  176.   fileString=HttpContext.Current.Server.UrlDecode(fileString);
  177.   
  178.   FileInfo fi = new FileInfo(MapPath(fileString));
  179.   
  180.   string originalName = Path.GetFileName(fileString);
  181.   string parentPath = fi.DirectoryName+"//";
  182.   
  183.   string originalPath = fi.FullName;
  184.   string finalPath = parentPath+updateString;
  185.   
  186.   if(DebugFile)
  187.   {
  188.    HttpContext.Current.Response.Write("<li/>rename file");
  189.    HttpContext.Current.Response.Write("<li/>updateString: "+updateString);
  190.    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);
  191.    HttpContext.Current.Response.Write("<li/>original name: "+originalName);
  192.    HttpContext.Current.Response.Write("<li/>parentPath: "+parentPath);
  193.    HttpContext.Current.Response.Write("<li/>originalPath: "+originalPath);
  194.    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);
  195.    
  196.    HttpContext.Current.Response.Write("<hr/>");
  197.   }
  198.   
  199.   if(updateString == originalName)return;

  200.   if(!File.Exists(finalPath))
  201.   {
  202.    fi.MoveTo(finalPath);
  203.    
  204.    Session[FileListSession] = null;
  205.     
  206.    SQ.Utility.GoBack("文件已重命名, 3 秒后返回, 还有 ", 3, 
  207.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  208.    return;
  209.   }
  210.   else
  211.   {
  212.    SQ.Utility.GoBack("已存在相同的文件名, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  213.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  214.   }
  215.  } // end void flMngUpdateFolderCmd
  216.  
  217.  void flMngNewFolderCmd(Object sender, DataListCommandEventArgs e) 
  218.  { 
  219.   string updateString = ((TextBox)e.Item.FindControl("flMngNewFolderTbx")).Text;
  220.   updateString = Regex.Replace(updateString, @"^/s+|/s+$", "");
  221.   
  222.   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;
  223.   folderString=HttpContext.Current.Server.UrlDecode(folderString);
  224.   

  225.   if(updateString!="")
  226.   {
  227.    DirectoryInfo di = new DirectoryInfo(MapPath(folderString));
  228.    
  229.    string destination = di.FullName+@"/"+updateString+@"/";
  230.       
  231.    if(!Directory.Exists(destination))
  232.    {
  233.     Directory.CreateDirectory(destination);
  234.     Session[FolderListSession] = null;
  235.      
  236.     Utility.GoBack("文件夹已创建, 3 秒后返回, 还有 ", 3, 
  237.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  238.      
  239.     return;
  240.    }
  241.    else
  242.    {
  243.     Utility.GoBack("已存在相同的文件夹, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  244.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  245.    }
  246.   } 
  247.  } // end void flMngUpdateFolderCmd
  248.  
  249.  void flMngDeleteFolderCmd(Object sender, DataListCommandEventArgs e) 
  250.  {
  251.   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;
  252.   folderString=HttpContext.Current.Server.UrlDecode(folderString);
  253.   
  254.   DirectoryInfo di = new DirectoryInfo(MapPath(folderString));
  255.      
  256.   if(di.Exists)
  257.   {
  258.    di.Delete(true);
  259.    Session[FolderListSession] = null;
  260.     
  261.    SQ.Utility.GoBack("文件夹已删除, 3 秒后返回, 还有 ", 3, 
  262.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  263.     
  264.    return;
  265.   }
  266.   else
  267.   {
  268.    SQ.Utility.GoBack("文件夹不存在, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  269.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  270.   }
  271.  } // end void flMngUpdateFolderCmd
  272.  
  273.  void flMngDeleteFileCmd(Object sender, DataListCommandEventArgs e) 
  274.  {
  275.   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;
  276.   fileString=HttpContext.Current.Server.UrlDecode(fileString);
  277.   
  278.   string finalPath = MapPath(fileString);
  279.   
  280.   if(DebugFile&flMngDebugLabel!=null)
  281.   {
  282.    HttpContext.Current.Response.Write("<li/>delete file");
  283.    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);
  284.    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);
  285.   }
  286.   
  287.   if(File.Exists(finalPath))
  288.   {
  289.    File.Delete(finalPath);
  290.    Session[FileListSession] = null;
  291.     
  292.    SQ.Utility.GoBack("文件已删除, 3 秒后返回, 还有 ", 3, 
  293.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  294.   }
  295.  } // end void flMngUpdateFolderCmd
  296.  
  297.  void flMngMoveFolderToRootCmd(Object sender, DataListCommandEventArgs e) 
  298.  {
  299.   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;
  300.   folderString=HttpContext.Current.Server.UrlDecode(folderString);
  301.   
  302.   DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));
  303.   
  304.   DirectoryInfo diForMove = new DirectoryInfo(MapPath(folderString));
  305.   
  306.   if(diRoot.FullName == diForMove.Parent.FullName+"//")
  307.   {
  308.    SQ.Utility.GoBack("该文件夹已在根目录, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  309.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  310.   }
  311.   else
  312.   {
  313.    try
  314.    {
  315.     diForMove.MoveTo(diRoot+diForMove.Name);
  316.     Session[FolderListSession] = null;
  317.     Utility.GoBack("文件夹已移到根目录, 3 秒后返回, 还有 ", 3, 
  318.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  319.    }
  320.    catch(Exception ex)
  321.    {
  322.     Utility.GoBack("该文件夹已在根目录, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  323.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  324.    }
  325.   }
  326.  } // end void flMngUpdateFolderCmd
  327.  
  328.  void flMngMoveFileToRootCmd(Object sender, DataListCommandEventArgs e) 
  329.  {
  330.   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;
  331.   fileString=HttpContext.Current.Server.UrlDecode(fileString);
  332.   
  333.   DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));
  334.   FileInfo fi = new FileInfo(MapPath(fileString));
  335.   
  336.   string finalPath = diRoot+fi.Name;
  337.   
  338.   if(DebugFile)
  339.   {
  340.    HttpContext.Current.Response.Write("<li/>Move To Root");
  341.    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);
  342.    HttpContext.Current.Response.Write("<li/>diRoot FullName: "+diRoot.FullName);
  343.    HttpContext.Current.Response.Write("<li/>fi FullName: "+fi.FullName);
  344.    HttpContext.Current.Response.Write("<li/>fi FullName: "+fi.DirectoryName+"//");
  345.    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);
  346.    
  347.    HttpContext.Current.Response.Write("<hr/>");
  348.   }
  349.   
  350.   if(diRoot.FullName==fi.DirectoryName+"//")
  351.   {
  352.    SQ.Utility.GoBack("该文件已在根目录, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  353.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  354.   }
  355.   else
  356.   {
  357.    try
  358.    {
  359.     fi.MoveTo(finalPath);
  360.     Session[FileListSession] = null;
  361.     Utility.GoBack("文件已移到根目录, 3 秒后返回, 还有 ", 3, 
  362.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  363.    }
  364.    catch(Exception ex)
  365.    {
  366.     Utility.GoBack("根目录存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  367.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  368.    }
  369.   }
  370.  } // end void flMngMoveFileToRootCmd
  371.  
  372.  void flMngMoveFolderToParentCmd(Object sender, DataListCommandEventArgs e) 
  373.  {
  374.   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;
  375.   folderString=HttpContext.Current.Server.UrlDecode(folderString);
  376.   
  377.   DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));
  378.   DirectoryInfo diForMove = new DirectoryInfo(MapPath(folderString));
  379.   DirectoryInfo diParent = diForMove.Parent;

  380.   
  381.   string moveToPath = diForMove.Parent.Parent.FullName+"//"+diForMove.Name;
  382.   if(diParent.FullName == moveToPath)
  383.   {
  384.    SQ.Utility.GoBack("已存在相同目录, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  385.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  386.   }
  387.   else
  388.   {
  389.    if(moveToPath.IndexOf(diRoot.FullName)<0)
  390.    {
  391.     Utility.GoBack("越权, 操作被取消, 3 秒后返回, 还有 ", 3, 
  392.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  393.     return;
  394.    }
  395.    try
  396.    {
  397.     diForMove.MoveTo(moveToPath);
  398.     Session[FolderListSession] = null;
  399.     Utility.GoBack("文件夹已移到父目录, 3 秒后返回, 还有 ", 3, 
  400.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  401.    }
  402.    catch(Exception ex)
  403.    {
  404.    SQ.Utility.GoBack("已存在相同目录, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  405.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  406.    }
  407.   }
  408.  } // end void flMngUpdateFolderCmd
  409.  
  410.  void flMngMoveFileToParentCmd(Object sender, DataListCommandEventArgs e) 
  411.  {
  412.   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;
  413.   fileString=HttpContext.Current.Server.UrlDecode(fileString);
  414.  
  415.   DirectoryInfo diRoot = new DirectoryInfo(MapPath(ManageRoot));
  416.   FileInfo fi = new FileInfo(MapPath(fileString));
  417.   DirectoryInfo di = new DirectoryInfo(fi.DirectoryName)
  418.   
  419.   string finalPath = di.Parent.FullName+"//"+fi.Name;
  420.   
  421.   if(DebugFile)
  422.   {
  423.    HttpContext.Current.Response.Write("<li/>Move To Parent");
  424.    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);
  425.    HttpContext.Current.Response.Write("<li/>fi.FullName: "+fi.FullName);
  426.    HttpContext.Current.Response.Write("<li/>di.FullName: "+di.FullName);
  427.    HttpContext.Current.Response.Write("<li/>di.Parent.FullName: "+di.Parent.FullName);
  428.    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);
  429.    HttpContext.Current.Response.Write("<hr/>");
  430.   }
  431.   
  432.   if(!File.Exists(finalPath))
  433.   {
  434.    if(finalPath.IndexOf(diRoot.FullName)<0)
  435.    {
  436.     Utility.GoBack("越权, 操作被取消, 3 秒后返回, 还有 ", 3, 
  437.      HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  438.     return;
  439.    }
  440.    else
  441.    {
  442.     try
  443.     {
  444.      fi.MoveTo(finalPath);
  445.      Session[FileListSession] = null;
  446.      Utility.GoBack("文件已移到父目录, 3 秒后返回, 还有 ", 3, 
  447.       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  448.     }
  449.     catch(Exception ex)
  450.     {
  451.      Utility.GoBack("已存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  452.       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  453.     }
  454.    }
  455.   }
  456.   else
  457.   {
  458.    SQ.Utility.GoBack("已存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  459.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  460.   }
  461.  } // end void flMngUpdateFolderCmd
  462.  
  463.  void flMngMoveFolderInCmd(Object sender, DataListCommandEventArgs e) 
  464.  {
  465.   string folderString = ((HtmlInputHidden)e.Item.FindControl("flMngUpdateFolderHid")).Value;
  466.   folderString=HttpContext.Current.Server.UrlDecode(folderString);
  467.   
  468.   RadioButtonList rbl = 
  469.   ((RadioButtonList)e.Item.FindControl("flMngRdoBtnLst"));
  470.   
  471.   DirectoryInfo diForMove = new DirectoryInfo(MapPath(folderString));
  472.   string forMovePath = MapPath(rbl.SelectedValue+diForMove.Name);
  473.   
  474.   if(DebugFile)
  475.   {
  476.    HttpContext.Current.Response.Write("<li/>Move in folder: "+rbl.SelectedValue);
  477.    HttpContext.Current.Response.Write("<li/>current folder: "+folderString);
  478.    HttpContext.Current.Response.Write("<li/>move in: "+forMovePath);
  479.   }
  480.   
  481.   if(rbl.SelectedValue=="")
  482.   {
  483.    SQ.Utility.GoBack("必须选择一个项目进行操作, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  484.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  485.     return;
  486.   }
  487.    
  488.   if(Directory.Exists(forMovePath))
  489.   {
  490.    SQ.Utility.GoBack("已存在相同目录, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  491.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  492.     return;
  493.   }
  494.   else
  495.   {
  496.    diForMove.MoveTo(forMovePath);
  497.    
  498.    Session[FolderListSession] = null;
  499.    SQ.Utility.GoBack("文件夹已成功移动, 3 秒后返回, 还有 ", 3, 
  500.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  501.    return
  502.   }
  503.  } // end void flMngUpdateFolderCmd
  504.  
  505.  void flMngMoveFileInCmd(Object sender, DataListCommandEventArgs e) 
  506.  {
  507.   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;
  508.   fileString=HttpContext.Current.Server.UrlDecode(fileString);

  509.   RadioButtonList rbl = 
  510.   ((RadioButtonList)e.Item.FindControl("flMngFileRdoBtnLst"));
  511.   
  512.   FileInfo fi = new FileInfo(MapPath(fileString));
  513.   
  514.   string finalPath = MapPath(rbl.SelectedValue)+fi.Name;
  515.   
  516.   if(DebugFile)
  517.   {
  518.    HttpContext.Current.Response.Write("<li/>Move File In Folder");
  519.    HttpContext.Current.Response.Write("<li/>fileString: "+fileString);
  520.    HttpContext.Current.Response.Write("<li/>rbl==null: "+(rbl==null));
  521.    HttpContext.Current.Response.Write("<li/>rbl.SelectedValue: "+rbl.SelectedValue);
  522.    HttpContext.Current.Response.Write("<li/>finalPath: "+finalPath);
  523.   }
  524.   
  525.   if(rbl.SelectedValue=="")
  526.   {
  527.    return;
  528.   }
  529.   
  530.   if(File.Exists(finalPath))
  531.   {
  532.    SQ.Utility.GoBack("已存在相同文件, 本次操作被取消, 3 秒后返回, 还有 ", 3, 
  533.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  534.     return;
  535.   }
  536.   else
  537.   {
  538.    fi.MoveTo(finalPath);
  539.    
  540.    Session[FileListSession] = null;
  541.    SQ.Utility.GoBack("文件已成功移动, 3 秒后返回, 还有 ", 3, 
  542.     HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  543.    return
  544.   }
  545.  } // end void flMngUpdateFolderCmd
  546.  
  547.  void flMngDownloadFileCmd(Object sender, DataListCommandEventArgs e) 
  548.  {
  549.   string fileString = ((HtmlInputHidden)e.Item.FindControl("flMngRenameFileHid")).Value;
  550.   fileString=HttpContext.Current.Server.UrlDecode(fileString);
  551.     
  552.   Utility.DownloadFile(fileString, true);
  553.  } // end void flMngDownloadFileCmd
  554.  
  555.  
  556.  void flMngItemCmd(Object s, DataListCommandEventArgs e)
  557.  {
  558.   switch (e.CommandName+"")
  559.   {    
  560.    case "NewSubFolder":
  561.     flMngNewFolderCmd(s, e);
  562.     break;
  563.    
  564.    case "flMngRenameFolderLb":
  565.     flMngRenameFolderCmd(s, e);
  566.     break;
  567.     
  568.    case "flMngDeleteFolder":
  569.     flMngMoveFolderToRootCmd(s, e);
  570.     break;
  571.     
  572.    case "MoveFolderToRoot":
  573.     flMngMoveFolderToRootCmd(s, e);
  574.     break;
  575.     
  576.    case "MoveFolderToParent":
  577.     flMngMoveFolderToParentCmd(s, e);
  578.     break;
  579.     
  580.    case "MoveFolderIn":
  581.     flMngMoveFolderInCmd(s, e);
  582.     break;
  583.   }
  584.   return;
  585.  }
  586.  
  587.  void flMngFileItemCmd(Object s, DataListCommandEventArgs e)
  588.  {
  589.   switch (e.CommandName+"")
  590.   {    
  591.    case "flMngRenameFile":
  592.     flMngRenameFileCmd(s, e);
  593.     break;
  594.     
  595.    case "flMngDeleteFile":
  596.     flMngDeleteFileCmd(s, e);
  597.     break;
  598.     
  599.    case "MoveFileToRoot":
  600.     flMngMoveFileToRootCmd(s, e);
  601.     break;
  602.     
  603.    case "MoveFileToParent":
  604.     flMngMoveFileToParentCmd(s, e);
  605.     break;
  606.     
  607.    case "MoveFileIn":
  608.     flMngMoveFileInCmd(s, e);
  609.     break;
  610.     
  611.    case "DownloadFile":
  612.     flMngDownloadFileCmd(s, e);
  613.     break;
  614.   }
  615.   return;
  616.  }
  617.  
  618.  void FileMoveFileMethod(Object s, EventArgs e)
  619.  {
  620.   if(flMngFileMoveInListRbl.SelectedValue=="")return;
  621.   
  622.   int totalCbx = flMngFileList.Items.Count;
  623.   
  624.   ArrayList alError = new ArrayList();
  625.   
  626.   for(int i=0; i<totalCbx; i++)
  627.   {
  628.    HtmlInputCheckBox hicb =
  629.     (HtmlInputCheckBox)((flMngFileList.Items[i]).FindControl("flMngFileCbx"));
  630.    
  631.    if(hicb.Checked)
  632.    {
  633.     string finalPath = flMngFileMoveInListRbl.SelectedValue+"//"+Path.GetFileName(hicb.Value);
  634.     if(File.Exists(finalPath))
  635.     {
  636.      alError.Add(finalPath);
  637.     }
  638.     else
  639.     {
  640.      File.Move(hicb.Value, finalPath);
  641.     }
  642.    }
  643.   } // end for
  644.   
  645.   if(alError.Count>0)
  646.   {
  647.    flMngInfoLabel.Text+=
  648.     "<h3 class='algc'>有 "+alError.Count+
  649.      "个 文件未能移动, 原因为存在同名文件, 文件名如下:</h3>";
  650.    for(int i=0, j=alError.Count; i<j; i++)
  651.    {
  652.     flMngInfoLabel.Text+="<li/>"+Path.GetFileName(alError[i]+"");
  653.    }
  654.   }
  655.    
  656.   Session[FileListSession] = null;
  657.   SQ.Utility.GoBack("操作完毕, 3 秒后返回, 还有 ", 3, 
  658.    HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  659.  
  660.   if(DebugFile)
  661.   {
  662.    HttpContext.Current.Response.Write("<li/>Move File Method: ");
  663.    HttpContext.Current.Response.Write(
  664.     "<li/>flMngFileMoveInListRbl.SelectedValue: "+flMngFileMoveInListRbl.SelectedValue);
  665.    HttpContext.Current.Response.Write(
  666.     "<li/>flMngFileList.Items.Count: "+flMngFileList.Items.Count);
  667.   }
  668.  }
  669.  
  670.  void FileMoveFileToRootMethod(Object s, EventArgs e)
  671.  {
  672.   
  673.   int totalCbx = flMngFileList.Items.Count;
  674.   
  675.   ArrayList alError = new ArrayList();
  676.   
  677.   for(int i=0; i<totalCbx; i++)
  678.   {
  679.    HtmlInputCheckBox hicb =
  680.     (HtmlInputCheckBox)((flMngFileList.Items[i]).FindControl("flMngFileCbx"));
  681.    
  682.    if(hicb.Checked)
  683.    {
  684.     string finalPath = MapPath(ManageRoot)+Path.GetFileName(hicb.Value);
  685.     if(File.Exists(finalPath))
  686.     {
  687.      alError.Add(finalPath);
  688.     }
  689.     else
  690.     {
  691.      File.Move(hicb.Value, finalPath);
  692.     }
  693.    }
  694.   } // end for
  695.   
  696.   if(alError.Count>0)
  697.   {
  698.    flMngInfoLabel.Text+=
  699.     "<h3 class='algc'>有 "+alError.Count+
  700.      "个 文件未能移动, 原因为存在同名文件, 文件名如下:</h3>";
  701.    for(int i=0, j=alError.Count; i<j; i++)
  702.    {
  703.     flMngInfoLabel.Text+="<li/>"+Path.GetFileName(alError[i]+"");
  704.    }
  705.   }
  706.    
  707.   Session[FileListSession] = null;
  708.   SQ.Utility.GoBack("操作完毕, 3 秒后返回, 还有 ", 3, 
  709.    HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  710.  }
  711.  
  712.  void FileMoveFileToParentMethod(Object s, EventArgs e)
  713.  {
  714.   int totalCbx = flMngFileList.Items.Count;
  715.   string rootPath = MapPath(ManageRoot);
  716.   ArrayList alError = new ArrayList();
  717.   
  718.   for(int i=0; i<totalCbx; i++)
  719.   {
  720.    HtmlInputCheckBox hicb =
  721.     (HtmlInputCheckBox)((flMngFileList.Items[i]).FindControl("flMngFileCbx"));
  722.    
  723.    if(hicb.Checked)
  724.    {
  725.     DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(hicb.Value));
  726.     
  727.     string finalPath = di.Parent.FullName+"//"+Path.GetFileName(hicb.Value);
  728.     
  729.     if(finalPath.IndexOf(rootPath)<0)
  730.     {
  731.      Utility.GoBack("越权, 操作被取消, 3 秒后返回, 还有 ", 3, 
  732.       HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  733.      return;
  734.     }
  735.     if(File.Exists(finalPath))
  736.     {
  737.      alError.Add(finalPath);
  738.     }
  739.     else
  740.     {
  741.      File.Move(hicb.Value, finalPath);
  742.     }
  743.    }
  744.   } // end for
  745.   
  746.   if(alError.Count>0)
  747.   {
  748.    flMngInfoLabel.Text+=
  749.     "<h3 class='algc'>有 "+alError.Count+
  750.      "个 文件未能移动, 原因为存在同名文件, 文件名如下:</h3>";
  751.    for(int i=0, j=alError.Count; i<j; i++)
  752.    {
  753.     flMngInfoLabel.Text+="<li/>"+Path.GetFileName(alError[i]+"");
  754.    }
  755.   }
  756.    
  757.   Session[FileListSession] = null;
  758.   SQ.Utility.GoBack("操作完毕, 3 秒后返回, 还有 ", 3, 
  759.    HttpContext.Current.Request.UrlReferrer+"", flMngInfoLabel);
  760.  }
  761. </script>
  762. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  763. <html xmlns="http://www.w3.org/1999/xhtml">
  764. <head>
  765. <meta http-equiv="Content-Typecontent="text/html; charset=utf-8" />
  766. <title>shawl.qiu template</title>
  767. <style type="text/css">
  768. /*<![CDATA[*/
  769.  @import "style/css.css";
  770. /*]]>*/
  771. </style>
  772. </head>
  773. <body>
  774.  <form runat="server">
  775.   <!-- Begin flMng -->
  776.    <asp:Label id="flMngDebugLabelrunat="server" />
  777.    <asp:Label id="flMngNavigatorLabelrunat="server" />
  778.    <asp:Label id="flMngInfoLabelrunat="server" />
  779.    <asp:PlaceHolder id="flMngPhrunat="server" />
  780.   
  781.   <div class="flMngFolderBar algr">
  782.    <asp:PlaceHolder id=flMngFolderPh runat=server
  783.     />
  784.   </div>
  785.  
  786.   <asp:DataList id="flMngFolderListrunat="server"
  787.    BorderColor="black"
  788.    CellPadding="5"
  789.    CellSpacing="5"
  790.    RepeatDirection="Horizontal"
  791.    RepeatLayout="Flow"
  792.    RepeatColumns="10"
  793.    ShowBorder="True"
  794.    OnEditCommand="flMngEditCmd"
  795.    OnItemCommand="flMngItemCmd"
  796.    >
  797.  
  798.    <HeaderTemplate>
  799.     <h3>目录:</h3>
  800.     <ol class="flMngFolderList">
  801.    </HeaderTemplate>
  802.    
  803.    <HeaderStyle >
  804.    </HeaderStyle>
  805.   
  806.    <AlternatingItemStyle>
  807.    </AlternatingItemStyle>
  808.     
  809.    <ItemTemplate>
  810.     <li>
  811.      <div class="fltr">
  812.       <asp:LinkButton id="flMngEditButtonrunat="server
  813.        Text="Edit" 
  814.        CommandName="Edit"
  815.        />
  816.      </div>
  817.      <href="?path=<%# DataBinder.Eval(Container.DataItem, "FolderRelativePath") %>">
  818.       <%# DataBinder.Eval(Container.DataItem, "FolderName") %>
  819.      </a>
  820.     </li
  821.    </ItemTemplate>
  822.    
  823.     <EditItemTemplate>
  824.     <li>
  825.      <href="?path=<%# DataBinder.Eval(Container.DataItem, "FolderRelativePath") %>">
  826.       <%# DataBinder.Eval(Container.DataItem, "FolderName") %>
  827.      </a>
  828.      <ul class="flMngEdit">
  829.       <li>
  830.        <span onclick="return confirm('确定要重命名文件夹吗?')">
  831.         <asp:LinkButton id=flMngUpdateFolderLb runat=server
  832.          Text="Rename:" 
  833.          CommandName="flMngRenameFolderLb" 
  834.          /> 
  835.        </span>
  836.        
  837.        <asp:TextBox id="flMngUpdateFolderTbxrunat="server"
  838.         Text=<%# DataBinder.Eval(Container.DataItem,"FolderName")%>
  839.         />
  840.         
  841.        <input type="hiddenid=flMngUpdateFolderHid runat=server
  842.         value=
  843.         <%# DataBinder.Eval(Container.DataItem,"FolderRelativePath")%>
  844.         />
  845.       </li>
  846.       <li>
  847.        <span onclick="return confirm('现在添加新文件夹吗?')">
  848.         <asp:LinkButton id=flMngNewFolderLb runat=server
  849.          Text="New Folder:" 
  850.          CommandName="NewSubFolder" 
  851.          /> 
  852.        </span>
  853.        <asp:TextBox id="flMngNewFolderTbxrunat="server"
  854.         />
  855.       </li>
  856.       <li
  857.        <span onclick="return confirm('确定要删除文件夹吗?')">
  858.         <asp:LinkButton id=flMngDeleteFolderLb runat=server
  859.          Text="Delete:" 
  860.          CommandName="flMngDeleteFolder" 
  861.          /> 
  862.          <%# DataBinder.Eval(Container.DataItem,"FolderRelativePath")%>
  863.        </span>
  864.       </li>
  865.       <li>
  866.        <span onclick="return confirm('现在移动文件夹到根目录吗?')">
  867.         <asp:LinkButton id=flMngMoveFolderToRootLb runat=server
  868.          Text="Move To Root:" 
  869.          CommandName="MoveFolderToRoot" 
  870.          /> 
  871.        </span>
  872.       </li>
  873.       <li>
  874.        <span onclick="return confirm('现在移动文件夹到父目录吗?')">
  875.         <asp:LinkButton id=flMngMoveFolderToParentLb runat=server
  876.          Text="Move To Parent:" 
  877.          CommandName="MoveFolderToParent" 
  878.          /> 
  879.        </span>
  880.       </li>
  881.       <li>
  882.        <span onclick="return confirm('现在移动文件夹至选定目录吗?')">
  883.         <asp:LinkButton id=flMngMoveFolderInLb runat=server
  884.          Text="Move Folder In:" 
  885.          CommandName="MoveFolderIn" 
  886.          /> 
  887.        </span>
  888.         
  889.        <asp:RadioButtonList id="flMngRdoBtnLstrunat="server"
  890.         DataValueField="FolderRelativePath" 
  891.         DataTextField="FolderName"
  892.         RepeatDirection="Horizontal"
  893.         />

  894.       </li>
  895.      </ul>
  896.     </li
  897.     </EditItemTemplate>
  898. <%--
  899.    <SeparatorTemplate
  900.    </SeparatorTemplate>
  901. --%>
  902.    <FooterTemplate>
  903.     </ol>
  904.    </FooterTemplate>
  905.   </asp:DataList>
  906.   
  907.   <div class="flMngUpload">
  908.    <asp:PlaceHolder id=flMngUploadPh runat=server />
  909.    <asp:PlaceHolder id=flMngEditBoxPh runat=server />
  910.   </div>
  911.     
  912.   <div class="flMngFilebar">
  913. <%--
  914.    <span onclick="return confirm('确定要移动文件吗?')">
  915.     <asp:LinkButton id=flMngMoveFileInLb runat=server
  916.      Text="Move File In:"
  917.      OnClick="FileMoveFileMethod"
  918.      /> 
  919.    </span>
  920. --%>
  921.    <asp:PlaceHolder id=flMngFileBar runat=server
  922.     />
  923.    <asp:RadioButtonList id=flMngFileMoveInListRbl runat=server 
  924.     DataTextField="FolderName"
  925.     DataValueField="FolderPhysicalPath"
  926.     RepeatDirection="Horizontal"
  927.     
  928.      />
  929.   </div>
  930.   
  931.   <asp:DataList id="flMngFileListrunat="server"
  932.    BorderColor="black"
  933.    CellPadding="5"
  934.    CellSpacing="5"
  935.    RepeatDirection="Horizontal"
  936.    RepeatLayout="Flow"
  937.    RepeatColumns="10"
  938.    ShowBorder="True"
  939.    OnEditCommand="flMngFileEditCmd"
  940.    OnItemCommand="flMngFileItemCmd"
  941.    >
  942.  
  943.    <HeaderTemplate>
  944.     <ol class="flMngFolderList">
  945.    </HeaderTemplate>
  946.    
  947.    <HeaderStyle >
  948.    </HeaderStyle>
  949.   
  950.    <AlternatingItemStyle>
  951.    </AlternatingItemStyle>
  952.     
  953.    <ItemTemplate>
  954.     <li>
  955.      <div class="fltr">
  956.       <asp:LinkButton id="flMngFileEditButton
  957.        Text="Edit" 
  958.        CommandName="Edit"
  959.        runat="server"
  960.        />
  961.      </div>
  962.      <input type="checkboxid="flMngFileCbxrunat="server"
  963.        value='<%# DataBinder.Eval(Container.DataItem, "FilePhysicalPath") %>'
  964.       />
  965.      <href="?id=editfile&filepath=<%# DataBinder.Eval(Container.DataItem, "FileRelativePath") %>">
  966.       <%# DataBinder.Eval(Container.DataItem, "FileName") %>
  967.      </a>
  968.     </li
  969.    </ItemTemplate>

  970.    <EditItemTemplate>
  971.     <li>
  972.      <href="?id=editfile&filepath=<%# DataBinder.Eval(Container.DataItem, "FileRelativePath") %>">
  973.       <%# DataBinder.Eval(Container.DataItem, "FileName") %>
  974.      </a>
  975.      <ul class="flMngEdit">
  976.       <li>
  977.        <span onclick="return confirm('确定要重命名文件吗?')">
  978.         <asp:LinkButton id=flMngRenameFileLb runat=server
  979.          Text="Rename:" 
  980.          CommandName="flMngRenameFile" 
  981.          /> 
  982.        </span>
  983.        
  984.        <asp:TextBox id="flMngRenameFileTbxrunat="server"
  985.         Text=<%# DataBinder.Eval(Container.DataItem,"FileName")%>
  986.         />
  987.         
  988.        <input type="hiddenid=flMngRenameFileHid runat=server
  989.         value=
  990.         <%# DataBinder.Eval(Container.DataItem,"FileRelativePath")%>
  991.         />
  992.       </li>
  993.       <li
  994.        <span onclick="return confirm('确定要删除文件吗?')">
  995.         <asp:LinkButton id=flMngDeleteFileLb runat=server
  996.          Text="Delete:" 
  997.          CommandName="flMngDeleteFile" 
  998.          /> 
  999.          <%# DataBinder.Eval(Container.DataItem,"FileRelativePath")%>
  1000.        </span>
  1001.       </li>
  1002.       <li>
  1003.        <span onclick="return confirm('现在移动文件到根目录吗?')">
  1004.         <asp:LinkButton id=flMngMoveFileToRootLb runat=server
  1005.          Text="Move To Root:" 
  1006.          CommandName="MoveFileToRoot" 
  1007.          /> 
  1008.        </span>
  1009.       </li>
  1010.       <li>
  1011.        <span onclick="return confirm('现在移动文件夹到父目录吗?')">
  1012.         <asp:LinkButton id=flMngMoveFileToParentLb runat=server
  1013.          Text="Move To Parent:" 
  1014.          CommandName="MoveFileToParent" 
  1015.          /> 
  1016.        </span>
  1017.       </li>
  1018.       <li>
  1019.        <span onclick="return confirm('现在移动文件至选定目录吗?')">
  1020.         <asp:LinkButton runat=server
  1021.          Text="Move File In Folder:" 
  1022.          CommandName="MoveFileIn" 
  1023.          /> 
  1024.        </span>
  1025.         
  1026.        <asp:RadioButtonList id="flMngFileRdoBtnLstrunat="server"
  1027.         DataValueField="FolderRelativePath" 
  1028.         DataTextField="FolderName"
  1029.         RepeatDirection="Horizontal"
  1030.         />
  1031.       </li>
  1032.       <li>
  1033.        <span onclick="return confirm('现在下载文件吗?')">
  1034.         <asp:LinkButton runat=server
  1035.          Text="--download file--" 
  1036.          CommandName="DownloadFile" 
  1037.          /> 
  1038.        </span>
  1039.       </li>
  1040.      </ul>
  1041.     </li
  1042.     </EditItemTemplate>
  1043. <%--
  1044.    <SeparatorTemplate
  1045.    </SeparatorTemplate>
  1046. --%>
  1047.    <FooterTemplate>
  1048.     </ol>
  1049.    </FooterTemplate>
  1050.   </asp:DataList>
  1051.   <div class="algc"><asp:Label id=flMngFooter runat=server /></div>
  1052.   <!-- End flMng -->
  1053.  </form>
  1054. </body>
  1055. </html>
  1056.