如何上传具有精确文件夹结构的整个文件夹?

时间:2019-05-25 10:29:43

标签: c# asp.net

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

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

上下文:Section1

 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);

0 个答案:

没有答案