c# - 如何上传具有确切文件夹结构的整个文件夹?
问题描述
我正在将整个文件夹上传到服务器。
该文件夹包含文件和子文件夹。
我希望它像在我的本地机器中一样被完全上传。
我尝试了 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);
解决方案
推荐阅读
- github - 如何在自托管案例中通过 url 参数加载自定义库
- spring-mvc - 从多部分请求标头和正文中删除无效字符
- java - 来自“https://services.gradle.org/distributions/gradle-6.1.1-all.zip”的 Gradle 分发。无法安装
- api - 如何通过 REST API 获取共享点文件的签出状态
- excel - 如何检测公式的结果值已更改
- python - 在数据帧上对 2 列进行元组以反转地理编码
- python - TF 2.6:model.summary 中不存在主干
- python - 用于重定向的 Django 自定义装饰器
- ansible - 与 json_query 一起使用时 set_fact 不起作用
- coq - 如何证明定理 plus_lt : forall n1 n2 m, n1 + n2 < m -> n1 < m /\ n2 < m