我正在尝试设置一个按钮,以便用户可以下载保存在服务器上的文件。
如果我更改为
我无法访问路径'C:\Windows\SysWOW64\inetsrv\test.html'。我尝试给NETWORK SERVICE赋予权限,但显示访问被拒绝。我的账户是服务器管理员账户。我看了一些帖子,但没有找到解决方法,或者我遗漏了什么步骤。请问正确使用WebcClient.DownloadFile的方法是什么?
protected void btnDownloadHtmlFile_Click(object sender, EventArgs e)
{
string path = @"D:\web\mytestwebsite.com\www\temp\test.html";
if (!File.Exists(path))
{
File.Create(path);
}
TextWriter tw = new StreamWriter(path);
tw.WriteLine("<head></head><body>test</body>");
tw.Close();
WebClient webclient = new WebClient();
webclient.DownloadFile(@"D:\web\mytestwebsite.com\www\temp\test.html", @"C:\web\test.html");
}
这意味着出现了以下错误:找不到路径“C:\web\test.html”
如果更改为其他路径,可能会出现同样的错误。
webclient.DownloadFile(new Uri("http://mytestwebsite.com/temp/test.html"), @"C:\web\test.html");
如果我更改为
webclient.DownloadFile(@"D:\web\mytestwebsite.com\www\temp\test.html", "test.html");
或者
webclient.DownloadFile(new Uri("http://mytestwebsite.com/temp/test.html"), "test.html");
我无法访问路径'C:\Windows\SysWOW64\inetsrv\test.html'。我尝试给NETWORK SERVICE赋予权限,但显示访问被拒绝。我的账户是服务器管理员账户。我看了一些帖子,但没有找到解决方法,或者我遗漏了什么步骤。请问正确使用WebcClient.DownloadFile的方法是什么?