我试图找出以下问题,但由于我一个月前才开始编程,所以我无法做到。
我有一个包含 20 个项目的列表框:
private void loadDownloadXMLListBox()
{
var items = new[] { "BARC", "DEV", "DOM", "EZJ", "GFS",
"IHG", "JD.", "LAD", "LLOY", "MRW",
"NXT", "OCDO", "RBS", "SMWH", "SPD",
"STAN", "SYR", "TALK", "TSCO", "WMH" };
foreach (var item in items) listDownloadXML.Items.Add(item);
listDownloadXML.SelectedIndex = -1;
}
这是我从网站下载单个选定文件的代码:
private void btnDownloadXML_Click(object sender, EventArgs e)
{
using (WebClient client = new WebClient())
{
client.DownloadFile("http://www.lse.co.uk/chat/" + listDownloadXML.SelectedItem,
@"..\..\sharePriceXML\" +
listDownloadXML.SelectedItem + ".xml");
}
MessageBox.Show("Download Completed! File has been placed in the folder sharePriceXML!");
}
我想单击“全部下载”按钮,然后将下载网站上的所有 20 个项目。我可以知道如何循环浏览列表框中的 20 个项目并将它们全部下载到一个文件夹中而不选择项目吗?谢谢你。