我已经尝试了很多方法来获得一个目录,我可以保存应用程序的.exe,需要留在那里,但我尝试说每个目录都拒绝访问。我应该在哪里保存应用程序数据?
我应该为此写什么路径?当然,必须有一个管理权限不正确的路径?我确信我已经看到过这样做..
我试过了什么?
这
Environment.GetFolderPath(
Environment.SpecialFolder.CommonApplicationData)
这
Path.GetTempPath()
这
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
谁能帮助吗?这里是我的完整代码,也许它与下载有关?
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);
}
沿着这些线路
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.
线异常通常得到一个例外:
client.DownloadFile(downloadUrl, savePath);
如果您试图轻松下载并执行任意可执行文件,则您与恶意软件无异。在windows中安装可执行文件的正确方法是.msi文件。 –
谁对恶意软件有任何评论?这也是一个个人项目,所以与恶意软件无关。 –
如果你正在下载更新到你的应用程序,你应该下载到用户临时目录 – Dawid