System.Net.WebException occurred
HResult=0x80131509
Message=Ett undantag uppstod under en WebClient-begäran.
Source=System
StackTrace:
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at System.Net.WebClient.DownloadFile(String address, String fileName)
at ConsoleApp1.Program.Main(String[] args) in C:\Use`enter code here`rs\user\Documents\Visual Studio `enter code here`2017\Projects\ConsoleApp1\ConsoleApp1\Program.cs:line 20
Inner Exception 1:
UnauthorizedAccessException: Åtkomst till sökvägen C:\Program Files (x86)\Leakoni\overwatch.txt nekas.
So i actually doing this: but where is the problem?
using (var client = new WebClient())
{
client.DownloadFile("https://leakoni.net/files/overwatch.txt", path + "overwatch.txt");
}
I don't really know what to do anymore tbh, where is my failure and how I'm supposed to fix it ;/
As per the comment from Martin Parkin, it looks like you're attempting to download a file into your program files folder. On modern windows operating systems this requires administrator permission. Even if you're logged on as an administrator you still have to approve the action in the GUI (try it now; using your normal windows GUI and a file you already have, copy it [the file] from e.g. your desktop and paste it into your Program Files:
Your code won't trigger the elevation process, it'll just get an access denied. Download to somewhere else instead (C:\temp) first, to satisfy yourself that it works before you set about implementing the necessary stuff to grant your program runtime access to writing data into Program Files subfolders (or change your program so it stores its data elsewhere - c:\users\username\appdata\roaming\yourcompany\
perhaps? )
I faced same issue before when trying to write xml file and fixed it by opening visual studio as a administrator right click then run as administrator.
User contributions licensed under CC BY-SA 3.0