c# - c#WebClient 将文件从 url 下载到所需目录不(真的)工作
问题描述
我是 C# 和 Visual Studio Windows 窗体的新手。我试图制作一个安装程序只是为了看看 c# 是如何工作的,但我有一个小问题。使用我的“程序”,您首先选择要下载文件的位置,然后单击下载按钮进行下载。所以我选择了我想要文件的位置,但它做了一些奇怪的事情。所以你选择文件夹并下载文件,但它会下载带有文本 CHROMEtest.txt 的文件(称为 test.txt)(我选择 chrome 作为我的安装目录)我的 chrome 文件夹在我的桌面文件夹中,所以我选择 chrome作为我的下载文件夹,但随后它作为 CHROMEtest.txt 安装在我的桌面上。这可能是因为我使用 textBox1.Text 作为目录。我将在这里发布代码以供理解。
字符串:
string url1 = "https://www.dropbox.com/s/f8f3x5qgmkeqis6/test.txt?dl=1";
string fileName1 = "text.txt";```
code:
oldBrowserDialog fbd = new FolderBrowserDialog();
private void folderbrowser_Click_1(object sender, EventArgs e)
{
if (fbd.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fbd.SelectedPath;
}
}
private void Install_Button_Click_1(object sender, EventArgs e)
{
if (textBox1.Text.Length > 0)
{
//Downloading file form Http Url
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(url1, textBox1.Text + fileName1);
//CompleteDownloading file form Http Url
}
else
{
MessageBox.Show("File path not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
i hope you guys can help me :D
解决方案
推荐阅读
- r - 计算R中租金价格的百分比增长?
- android - 将 Java 库与 Kotlin Multiplatform 一起使用
- angular8 - 如何在 Angular 中管理嵌套的 formGroup?
- php - 断开 Laravel 连接
- python - Django - 从 values() 函数返回子级列表?
- vue.js - 使用 vue-cli 和 vue-cli-service 是一种不好的做法吗?
- c++ - 用其他派生类C++重载基类的成员函数
- javascript - 如何在正常函数调用之前显示一些东西而不是之后停止显示?
- python - Tkinter 按钮颜色
- python - PyQt5 QGridLayout 大小不正确