我对下面的代码块感到困惑,因为它为什么下载网页的内容而不是文件本身。我创建了包含一些文本的虚拟文件,然后下载它,但是当我打开下载文件时,我没有看到我写的任何文本,但它有奇怪的网络语言标签。
private bool DownloadCSVfile()
{
bool downloadOk = false;
WebClient client = null;
try
{
client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
client.DownloadFile(myURL, CSVfile);
if (File.Exists(CSVfile))
downloadOk = true;
else
downloadOk = false;
}
catch (Exception error)
{
downloadOk = false;
string err = error.Message;
}
//release resource
if (client != null)
{
client.Dispose();
client = null;
}
//
if (downloadOk == true)
{
return true;
}
else
{
return false;
}
}