コード例 #1
0
        private void ShowFtpClientDirectories(string cmd, string currentDirectory)
        {
            System.Drawing.Icon icon = FileHelp.GetDirectoryIcon();

            //清空区域
            localDirectoryList.Items.Clear();


            var directories = Directory.GetDirectories(currentDirectory);

            foreach (var directory in directories)
            {
                DirectoryInfo di = new DirectoryInfo(directory);

                StackPanel sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                sp.Tag         = di.Name;

                Image img = new Image();
                img.Source = BitmapToBitmapSource(icon.ToBitmap());

                Label lb = new Label();
                lb.FontSize = 16;
                lb.Content  = di.Name;

                sp.Children.Add(img);
                sp.Children.Add(lb);
                localDirectoryList.Items.Add(sp);
            }
            var files = Directory.GetFiles(currentDirectory);

            foreach (var file in files)
            {
                System.Drawing.Icon fileIcon = FileHelp.GetFileIcon(file);
                FileInfo            fi       = new FileInfo(file);
                StackPanel          sp       = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                sp.Tag         = fi.Name;

                Image img = new Image();
                img.Source = BitmapToBitmapSource(fileIcon.ToBitmap());

                Label lb = new Label();
                lb.FontSize = 16;
                lb.Content  = fi.Name;

                sp.Children.Add(img);
                sp.Children.Add(lb);

                localDirectoryList.Items.Add(sp);
            }
        }
コード例 #2
0
        private void ShowFtpServerDirectories()
        {
            serverListBox.Items.Clear();

            var ftpRequest     = CreateFtpWebRequest(_ftpUrl, WebRequestMethods.Ftp.ListDirectoryDetails);
            var ftpResponse    = GetFtpWebResponse(ftpRequest);
            var responseStream = ftpResponse.GetResponseStream();

            StreamReader sr = new StreamReader(responseStream);
            var          s  = sr.ReadToEnd();

            string[] ftpDir = s.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            System.Drawing.Icon icon = FileHelp.GetDirectoryIcon();
            foreach (var dir in ftpDir)
            {
                string[] parseDir = ParseMSDosLIST(dir);
                string   year     = parseDir[0];
                string   time     = parseDir[1];
                string   size     = parseDir[2];
                string   name     = parseDir[3];

                if (size.ToLower().Contains("<dir>"))
                {
                    //文件夹
                    StackPanel sp = new StackPanel();
                    sp.Orientation = Orientation.Horizontal;
                    sp.Tag         = name;

                    Image img = new Image();
                    img.Source = BitmapToBitmapSource(icon.ToBitmap());

                    Label lb = new Label();
                    lb.FontSize = 16;
                    lb.Content  = name;

                    sp.Children.Add(img);
                    sp.Children.Add(lb);
                    serverListBox.Items.Add(sp);
                }
                else
                {
                    System.Drawing.Icon fileIcon = FileHelp.GetFileIcon(name);

                    //文件
                    StackPanel sp = new StackPanel();
                    sp.Orientation = Orientation.Horizontal;
                    sp.Tag         = name;

                    Image img = new Image();
                    img.Source = BitmapToBitmapSource(fileIcon.ToBitmap());

                    Label lb = new Label();
                    lb.FontSize = 16;
                    lb.Content  = name;

                    sp.Children.Add(img);
                    sp.Children.Add(lb);
                    serverListBox.Items.Add(sp);
                }

                //SetServerDirectories(dir);
            }
        }