首页 > 解决方案 > 如何上传具有确切文件夹结构的整个文件夹?

问题描述

我正在将整个文件夹上传到服务器。
该文件夹包含文件和子文件夹。
我希望它像在我的本地机器中一样被完全上传。

我尝试了 FolderBrowserDialog 然后是文件夹复制逻辑。
它在本地机器上运行良好,但部署后我得到未处理的异常。

上下文:第 1 节

 try
            {var t = new Thread((ThreadStart)(() =>
                {
                    FolderBrowserDialog fbd = new FolderBrowserDialog();
                    if (fbd.ShowDialog() == DialogResult.OK)
                    {
                        //foreach (var path in Directory.GetFiles(fbd.SelectedPath))
                        //{
                        //    //Console.WriteLine(path); // full path
                        //    //Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
                        //}
                    }
                    else
                    {

                        }
                        //fbd.RootFolder = System.Environment.SpecialFolder.MyComputer;
                        //fbd.ShowNewFolderButton = true;
                        //if (fbd.ShowDialog() == DialogResult.Cancel)
                        //    return;

                        selectedPath = fbd.SelectedPath;
                    }));
                    t.SetApartmentState(ApartmentState.STA);
                    t.Start();
                    t.Join();
                    //  ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup();", true);
                    FilesBulkUpload(selectedPath);
    private void FilesBulkUpload(string path)
            { try
                { if (path != null)
                    {
                        string lastFolderName = Path.GetFileName(path);
                        Copyfolder(path, @"D:\Sneha\test\" + lastFolderName,true);
                        MessageBox.Show("Folder Uploaded Successfully");
                    }
                }
                catch (Exception ex)
                {
                    LogError(ex);
                }
            }
    Copyfolder logic:
     if (Directory.Exists(SourcePath))
                    {
                        if (Directory.Exists(DestinationPath) == false)
                            Directory.CreateDirectory(DestinationPath);
                        foreach (string fls in Directory.GetFiles(SourcePath))
                        {     FileInfo flinfo = new FileInfo(fls);
                            string ext = flinfo.Extension;
                            if (ext`enter code here` == ".exe" || ext == ".zip")
                            {
                                MessageBox.Show("Please exclude files like with .exe, .zip extension");
                            }
                            else
                            {
                                flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                            }
                        }
                        foreach (string drs in Directory.GetDirectories(SourcePath))
                        {
                            DirectoryInfo diDi = new DirectoryInfo(drs);

标签: c#asp.net

解决方案


推荐阅读