如何下载文件,然后将其保存到我想要的位置?我正在使用 Windows 窗体、Web 应用程序。
我知道我可以使用以下代码下载它:
WebClient wClient = new WebClient();
wClient.DownloadFile("WebLinkHere", @"C:\File.txt");
但我想要一个像按 CTRL+S 时那样的保存框。
您可以使用保存文件对话框班级。例子:
var dialog = new SaveFileDialog();
dialog.Filter = "Archive (*.rar)|*.rar";
var result = dialog.ShowDialog(); //shows save file dialog
if(result == DialogResult.OK)
{
Console.WriteLine ("writing to: " + dialog.FileName); //prints the file to save
var wClient = new WebClient();
wClient.DownloadFile("WebLinkHere", dialog.FileName);
}
will show next dialog and if you search for next folder
![enter image description here](https://i.stack.imgur.com/HDOhu.png)
应用程序将打印:
writing to: C:\Temp\archiveName.rar
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)