我尝试了多种方法来获取一个目录,在该目录中可以保存需要保留在那里的应用程序的 .exe,但我尝试的每个目录都显示访问被拒绝。
我应该为此写入什么路径?肯定存在管理员权限不正确的路径吗?我确信我以前见过这样做的。
我尝试了什么?
这
Environment.GetFolderPath(
Environment.SpecialFolder.CommonApplicationData)
Run Code Online (Sandbox Code Playgroud)
这
Path.GetTempPath()
Run Code Online (Sandbox Code Playgroud)
和这个
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?这是我的完整代码,也许它与下载有关?
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);
}
Run Code Online (Sandbox Code Playgroud)
通常会遇到这样的异常
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. …Run Code Online (Sandbox Code Playgroud) 我最近一直在使用Carbon来显示人性化的时间字符串,但是由于某种原因,我只能让它显示主要因素,例如,我有一个日期,它需要显示距该日期还有多长时间。因此,例如,如果距离现在6天4小时32分钟,则当前仅显示“ 6天”。
我将如何显示它的小时数,也可能显示分钟数?当它只给您几天的时间时,这看起来太恐怖了,许多人可能想了解更多像小时和秒吗?
我在Carbon文档上找不到任何内容。我什至在laravel 5.3视图中使用它。
这是我的代码:
{{ \Carbon\Carbon::createFromTimeStamp(strtotime($item->created_at))->diffForHumans() }}
Run Code Online (Sandbox Code Playgroud)