gpt4 book ai didi

c# - WebClient 有问题

转载 作者:太空宇宙 更新时间:2023-11-03 15:31:32 25 4
gpt4 key购买 nike

我正在尝试为 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 还有一些可能有用的参数,为简洁起见我忽略了这些参数。我也没有在此处放置任何错误处理,因此您也需要这样做。

关于c# - WebClient 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33653497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com