我正在尝试为RADAR Images等制作Image Archive(r)。WebClient似乎对我有问题。或者我不知道我在做什么。
WebClient wc = new WebClient();
{
wc.Headers.Add("User-Agent: Other");
wc.DownloadFile("http://www.weather.gov/images/dlh/WxStory/FileL.png?", browserFileDialog.SelectedPath() + ".png");
}
每当我下载文件时,我都有一个“浏览文件”对话框。它将保存到桌面,并获得在“浏览文件对话框”中选择的文件夹的名称。任何帮助,将不胜感激。
编辑:我忘了说,我希望用户能够选择将其保存到的位置。
您可以使用SaveFileDialog获取所需的路径:
using (SaveFileDialog sfd = new SaveFileDialog())
{
// This only allows you to choose PNG, you may want to change it.
sfd.Filter = "Image Files (*.png)|*.png";
DialogResult result = sfd.ShowDialog();
if (result == DialogResult.OK)
{
using (WebClient wc = new WebClient())
{
wc.Headers.Add("User-Agent: Other");
wc.DownloadFile("http://www.weather.gov/images/dlh/WxStory/FileL.png?", sfd.FileName);
}
}
}
SaveFileDialog还有更多可能有用的参数,为简洁起见,我错过了这些参数。我也没有在这里进行错误处理,因此您也需要这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句