예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckAccount();

            if (!string.IsNullOrEmpty(Request["lib"]))
            {
                _path = HttpUtility.HtmlDecode(Request["lib"]);
            }
            else
            {
                _path = Request.PhysicalApplicationPath + "LIB\\";
            }

            if (!Directory.Exists(_path))
            {
                if (File.Exists(_path))
                {
                    string path = Request.Url.ToString();
                    path = path.Substring(0, path.LastIndexOf('/') + 1) + _path.Substring(Request.PhysicalApplicationPath.Length);
                    Response.Redirect(path);
                }
            }
            else
            {
                DirectoryInfo   info = new DirectoryInfo(_path);
                DirectoryInfo[] dirs = info.GetDirectories();
                List <Data>     data = new List <Data>();
                if (_path != Request.PhysicalApplicationPath + "LIB\\")
                {
                    string url = _path;
                    if (url[url.Length - 1] == '\\')
                    {
                        url = url.Substring(0, url.Length - 1);
                    }
                    if (_path.LastIndexOf('\\') > 0)
                    {
                        url = url.Substring(0, _path.LastIndexOf('\\') + 1);
                    }
                    data.Add(new Data()
                    {
                        Title = "..",
                        Url   = "~/Lib.aspx?lib=" + HttpUtility.HtmlEncode(url)
                    });
                }
                foreach (DirectoryInfo di in dirs)
                {
                    data.Add(new Data()
                    {
                        Title = di.Name,
                        Url   = "~/Lib.aspx?lib=" + HttpUtility.HtmlEncode(di.FullName)
                    });
                }
                FileInfo[] files = info.GetFiles();
                foreach (FileInfo fi in files)
                {
                    data.Add(new Data()
                    {
                        Title = fi.Name,
                        Url   = "~/Lib.aspx?lib=" + HttpUtility.HtmlEncode(fi.FullName)
                    });
                }
                Dir.DataSource = data;
                Dir.DataBind();
            }
        }