private TreeNode AddNodes(string path, TreeNode parentNode)
        {
            FileList objList = new FileList(path, "*.*");
            TreeNode node = new TreeNode(path, path);

            for (int index = 0; index < objList.Directories.Length; index++)
            {
                string directory              = objList.Directories[index];
                TreeNode objChildNode         = new TreeNode(directory, path + "\\" + directory + "\\");
                objChildNode.PopulateOnDemand = true;
                objChildNode.Target           = "_blank";

                parentNode.ChildNodes.Add(objChildNode);
            }

            foreach (string file in objList.Files)
            {
                TreeNode objChildNode = new TreeNode(file, path + "\\" + file);
                parentNode.ChildNodes.Add(objChildNode);
            }
            return node;
        }
Esempio n. 2
0
        protected void ParseHTTPPage(string directory, string filter)
        {
            try
            {
                string[] filterlist = filter.Split(';');
                if (!FileList.IsHTMLContent(directory))
                {
                    directory = GetPath(directory);
                }

                string uristring = ExtractUrifromUrl(directory);

                WebClient client   = new WebClient();
                byte[]    pagedata = client.DownloadData(directory);
                string[]  hrefs    = ExtractHrefsFromPage(pagedata);

                ArrayList dirs  = new ArrayList();
                ArrayList files = new ArrayList();
                foreach (string uri in hrefs)
                {
                    if (uri.EndsWith("/"))
                    {
                        //	handle the directory
                        if (uri.StartsWith(uristring))
                        {
                            dirs.Add(uri.Substring(uristring.Length).Trim('/'));
                        }
                    }
                    else
                    {
                        string file = Path.GetFileName(uri);
                        foreach (string query in filterlist)
                        {
                            if (System.Text.RegularExpressions.Regex.IsMatch(file, "." + query.Replace(".", "\\."), RegexOptions.IgnoreCase))
                            {
                                files.Add(file);
                                break;
                            }
                        }
                    }
                }

                _directories = new string[dirs.Count];
                dirs.CopyTo(_directories);
                System.Array.Sort(_directories);

                _files = new string[files.Count];
                files.CopyTo(_files);
                System.Array.Sort(_files);

                _basedirectory = directory;
                if (!_basedirectory.EndsWith("/"))
                {
                    _basedirectory += "/";
                }
            }
            catch (Exception except)
            {
                System.Diagnostics.Trace.WriteLine("Exception parsing URL: " + except.Message);
            }
            return;
        }