从Web下载文件,然后使用“保存文件”对话框进行保存? [英] Download file from web and then save with a save file dialog box?
本文介绍了从Web下载文件,然后使用“保存文件”对话框进行保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何下载文件,然后将其保存到我想要的任何位置?我正在使用Windows窗体,Web应用程序。
How can I download a file, then save it to wherever I want? I am using Windows Form, Web Application.
我知道我可以使用以下代码下载它:
I know I can download it with this code:
WebClient wClient = new WebClient();
wClient.DownloadFile("WebLinkHere", @"C:\File.txt");
但是我想要一个保存框,例如当您按CTRL + S时。
But I want a save box like when you press CTRL+S.
推荐答案
您可以使用 SaveFileDialog 类。示例:
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);
}
将显示下一个对话框,如果您搜索下一个文件夹
< img src = https://i.stack.imgur.com/HDOhu.png alt =在此处输入图片描述>
will show next dialog and if you search for next folder
应用程序将打印:
writing to: C:\Temp\archiveName.rar
这篇关于从Web下载文件,然后使用“保存文件”对话框进行保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文