我单击按钮时尝试下载文件,但是抛出UnauthorizedAccessException
并拒绝访问C:\User\...
。
private void button1_Click(object sender, EventArgs e)
{
WebClient Client = new WebClient();
string Download = "http://...";
string Location = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Zentrix\Update";
Directory.GetAccessControl(Location);
Client.DownloadFile(Download, Location);
if (!Directory.Exists(Location))
{
DirectoryInfo Folder = Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Zentrix");
}
this.Close();
}