0

我正在winforms中开发一个文件传输应用程序,我想添加一个下载文件夹的功能,到目前为止我能够实现文件夹的上传,因为这个过程是在客户端完成的,但是下载是不同的故事,顺便说一句,我正在使用 C# 和 brecham.obex 库。

 public void UploadFolder(string directory)
        {
            string[] directoryArray = Directory.GetDirectories(directory);

            if (directoryArray.Length != 0)
            {
                UploadDelegate up = delegate(string d)
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(d);
                    FileInfo[] fileInfo = directoryInfo.GetFiles();
                    string substr = parentFolder;
                    string di = directoryInfo.FullName;

                    int start = di.IndexOf(parentFolder);
                    string result = di.Substring(start);

                    session.SetPath(BackupFirst.DoNot, result, IfFolderDoesNotExist.Create);

                    foreach (FileInfo fi in fileInfo)
                    {

                        session.PutFile(fi.FullName);
                    }
                };
                up(directory);
                foreach (var dir in directoryArray)
                {
                    up(dir);
                    UploadFolder(dir);
                }
            }
        }


        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderbrowse = new FolderBrowserDialog();
            string folderName;
            if (folderbrowse.ShowDialog() == DialogResult.OK)
            {

                startPath = folderbrowse.SelectedPath;
                DirectoryInfo info = new DirectoryInfo(startPath);
                DirectoryInfo folder = new DirectoryInfo(startPath);
                folderName = folder.Name;
                parentFolder = "\\" + folderName;
                bgWorker.RunWorkerAsync();
            }
        }



        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            UploadFolder(startPath);

        }

        private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            session.SetPathReset();
            RefreshFolder();
        }
4

0 回答 0