ITeye博客

C# 隐藏文件夹

leavingme · 2008-04-22 21:05 · Markdown

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class getDirectory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string path = Request.QueryString["path"];

        if(path == null || path == "")
            path = @"C:\Windows";       

        DirectoryInfo TheFolder = new DirectoryInfo(path);
        if (!TheFolder.Exists)
            throw new DirectoryNotFoundException("Folder not found: " + path);

        string info = "<?xml version=\"1.0\"?><tree>";
        foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
        {
            //判读是否是隐藏文件夹
            if(NextFolder.Attributes.ToString().IndexOf("Hidden") == -1)
                info += "<tree text=\"" + NextFolder.Name + "\" src=\"" + NextFolder.FullName + "\"/>";
        }

        info += "</tree>";
        Response.Clear();
        Response.ContentType="text/xml";
        Response.Charset="UTF-8";
        Response.Write(info);
        Response.End();
    }
}

陈源 2008-04-22 21:05 发表评论

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。