⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deeptreehandler.cs

📁 酒店管理系统 酒店管理系统
💻 CS
字号:
using System;
using System.Web;
using System.Web.UI;
using System.Xml;
using System.Text;
using CSharpLib.Util;
using System.IO ;
using System.Runtime.InteropServices;
using System.Web.Security ;


namespace file.Handler
{
	public class kernel32 
	{
		[DllImport("kernel32.Dll")]
		public static extern int GetDriveType (String strDrive);
	}
	/// <summary>
	/// DeepTreeHandler 的摘要说明。
	/// </summary>
	public class DeepTreeHandler : IHttpHandler
	{

		private const string strTreeBegin = "<?xml version=\"1.0\" ?><Tree TreeId=\"essetree\">";
		private const string strTreeEnd = "</Tree>";		
		private const string strParentNode = "<TreeNode  MainImgSrc=\"{3}\" Title=\"{0}\" Href=\"PowerFileManage.aspx?path={1}\" NodeXmlSrc=\"GetXmlForm.aspx?path={2}\" />" ;
		private const string strNode	 = "<TreeNode   MainImgSrc=\"{2}\" Title=\"{0}\" Href=\"PowerFileManage.aspx?path={1}\"  />" ;

		private bool uf_HasChild(string strPath)
		{			
			try 
			{
				DirectoryInfo dinfo = new DirectoryInfo(strPath) ;			
				if(dinfo.GetDirectories().Length == 0)
					return false ;  
				else
					return true ;			
			}
			catch
			{
				return false ;
			}
				
		}
		
		private DirectoryInfo[] SortDir( DirectoryInfo[] dirLists) 
		{
			if (dirLists.Length < 2)
				return dirLists ;
			DirectoryInfo dirTmp ;
			DirectoryInfo dirExchange ;
			int iCurrent ;
			for ( int i = 0 ; i < dirLists.Length ; i++ )
			{				
				iCurrent = 0 ;
				dirTmp = dirLists[iCurrent] ;

				for ( int j = 1 ; j < dirLists.Length - i ; j++)
				{
					if ( dirTmp.Name.CompareTo(dirLists[j].Name) > 0 )
					{
						dirExchange = dirLists[j] ;
						dirLists[j] = dirTmp ;
						dirLists[iCurrent] = dirExchange ;
						iCurrent = j ;
					}
					else if ( dirTmp.Name.CompareTo(dirLists[j].Name) < 0 )
					{
						iCurrent = j ;
						dirTmp = dirLists[iCurrent] ;
					}
				}
			}

			return dirLists ;
		}
	    public void ProcessRequest(System.Web.HttpContext context)
        {
            string strPath = context.Request.Path.ToLower();
			string strName,strUrl,strXmlPath ;
			System.Web.UI.Page tmpPage = new Page() ;
            
			if(strPath.EndsWith("/getxmlform.aspx"))
			{
				context.Response.ContentType = "text/xml";					
				context.Response.Write(strTreeBegin);

				if ( context.Request["path"] == null)
				{
					strName = "我的电脑" ; 
					strUrl =  HttpUtility.UrlEncode("###") ;
					strXmlPath = StringUtil.XmlEncode("computer");
					context.Response.Write(String.Format(strParentNode,strName,strUrl,strXmlPath,"./pic/computer.jpg"));
					strName = "根目录" ; 
					strUrl = StringUtil.XmlEncode(tmpPage.Server.MapPath(".\\"));
					strXmlPath = StringUtil.XmlEncode(tmpPage.Server.MapPath(".\\"));
					context.Response.Write(String.Format(strParentNode,strName,strUrl,strXmlPath,"./pic/root.JPG"));					
				}
				else if( context.Request["path"] == "computer")
				{
					string[] drives = Directory.GetLogicalDrives();						
					foreach (string str in drives) 
					{					
						strName = str ; 
						strUrl =  HttpUtility.UrlEncode(str); ;
						strXmlPath = StringUtil.XmlEncode(str);
						int iType = kernel32.GetDriveType(strName) ;

						if (iType==2)
						{
							if (uf_HasChild(strName))
								context.Response.Write(String.Format(strParentNode,strName,strUrl,strXmlPath,"./pic/a.JPG"));
							else
								context.Response.Write(String.Format(strNode,strName,strUrl,"./pic/a.JPG"));

						}
						else if (iType==3)
						{						
							if (uf_HasChild(strName))
                                context.Response.Write(String.Format(strParentNode,strName,strUrl,strXmlPath,"./pic/disk.JPG"));
							else
								context.Response.Write(String.Format(strNode,strName,strUrl,"./pic/disk.JPG"));
						}
						else if (iType==5)
						{
							if (uf_HasChild(strName))
								context.Response.Write(String.Format(strParentNode,strName,strUrl,strXmlPath,"./pic/cd.JPG"));
							else
								context.Response.Write(String.Format(strNode,strName,strUrl,"./pic/cd.JPG"));
						}
					}							
				}				
				else
				{				
					string strExpPath = context.Request["path"] ;
					DirectoryInfo[] dirLists ;

					DirectoryInfo dinfo = new DirectoryInfo(strExpPath) ;
					dirLists = dinfo.GetDirectories() ;   			
					dirLists = SortDir(dirLists) ;
					
					foreach(DirectoryInfo dirInfo in dirLists)
					{
						strName = StringUtil.XmlEncode(dirInfo.Name) ; 
						strUrl =  HttpUtility.UrlEncode(dirInfo.FullName);  ;
						strXmlPath = strUrl ;//StringUtil.XmlEncode(dirInfo.FullName);
						if (uf_HasChild(dirInfo.FullName))
                            context.Response.Write(String.Format(strParentNode,strName,strUrl,strXmlPath,"./pic/file.JPG"));
						else
							context.Response.Write(String.Format(strNode,strName,strUrl,"./pic/file.JPG"));
					}		
				}

				context.Response.Write(strTreeEnd);
				tmpPage.Dispose() ;
			}
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -