我是新手,所以我敢肯定这是我所缺少的非常基本的东西。
我有一个简单的程序来运行一个csv
包含图像链接的文件,以将这些图像保存在指定的保存文件位置。
我正在将包含 的单元格解析url
为List<string[]>
.
如果我把GetImage(@"http://www.example.com/picture.jpg", 1)
我的GetImage
功能按它应该的方式执行。当我尝试使用循环并传入str[0]
变量时,我收到有关路径中非法字符的错误。
我用 aMessageBox
告诉我有什么区别,据我所知,当我将它传递给str[0]
函数时,它会添加双引号(即显示“http://www.example.com”而不是http ://www.example.com就像我只发送一个字符串时一样。
我究竟做错了什么?
private void button2_Click(object sender, EventArgs e)
{
string fileName = textBox1.Text;
folderBrowserDialog1.ShowDialog();
string saveLocation = folderBrowserDialog1.SelectedPath;
textBox2.Text = saveLocation;
List<string[]> file = parseCSV(fileName);
int count = 0;
foreach (string[] str in file)
{
if (count != 0)
{
GetImage(str[0], str[4]);
}
count++;
}
//GetImage(@"http://www.example.com/picture.jpg", "1");
}
private void GetImage(string url, string prodID)
{
string saveLocation = textBox2.Text + @"\";;
saveLocation += prodID + ".jpg";
WebClient webClt = new WebClient();
webClt.DownloadFile(url, saveLocation);
}