当我在项目中使用webclients并运行时,它说“访问被拒绝”,没有别的,它也从我的计算机中删除 这是代码
using (var client = new WebClient())
{
client.DownloadFile("example.com/a.txt", "a.txt");
}
编辑: 我不认为它与代码有关,我认为在这里将Webclient声明为自己输入代码时会得到标记
var client = new WebClient()
它本身不起作用
enter code here
enter code here
答案 0 :(得分:0)
在此示例中,请确保运行该应用程序的用户帐户确实具有将文件写入文件夹C:\ drive的权限。
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential("UserName", "Password");
client.DownloadFile(new Uri("http://www.example.com/a.txt"), @"c:\a.txt");
}
答案 1 :(得分:0)
您的问题与以下堆栈溢出问题类似。 您可以尝试以下问题的答案吗?
链接:Reading a remote text file line by line and comparing with inputbox entry