I tried many ways to get a directory where I can save the .exe application, which should remain there, but every single file I try to say is prohibited.
Which way should I write for this? Of course, there should be a way when administrator permission is not suitable? I am sure I saw how this is done before.
What have i tried?
it
Environment.GetFolderPath(
Environment.SpecialFolder.CommonApplicationData)
it
Path.GetTempPath()
And this one
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Can anyone help here? here is my complete code, maybe it has something to do with the download?
string downloadUrl = "http://example.com/example.txt";
string savePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Fox/example.txt";
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
using (var client = new WebClient())
{
client.DownloadFile(downloadUrl, savePath);
Process.Start(savePath);
}
Usually getting an exception on these lines
System.Net.WebException occurred
HResult=0x80131509
Message=An exception occurred during a WebClient request.
Source=System
StackTrace:
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at System.Net.WebClient.DownloadFile(String address, String fileName)
at App.Program.Main(String[] args) in c:\users\user\documents\visual studio 2017\Projects\App\App\Program.cs:line 26
Inner Exception 1:
UnauthorizedAccessException: Access to the path 'C:\Users\User\App\example.txt' is denied.
Exclusion Line:
client.DownloadFile(downloadUrl, savePath);
source
share