c# - System.Net.WebClient.DownloadFile 未下载
问题描述
我正在尝试使用 xamarin 通过 android 从我的服务器下载文件,我没有错误,但我没有找到它应该在的任何文件。
我正在使用该代码:
System.Net.WebClient Client = new System.Net.WebClient();
Console.WriteLine("Start downloading...");
try
{
var documentsFolder = System.Environment.GetFolderPath (System.Environment.SpecialFolder.MyDocuments);
if(!File.Exists(documentsFolder))
Directory.CreateDirectory(documentsFolder);
var fileNameAndPath = Path.Combine (documentsFolder, "tmpfile");
Client.DownloadFile(new Uri(url), fileNameAndPath);
}
catch(System.Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
while(e.InnerException!=null)
{
e=e.InnerException;
System.Diagnostics.Debug.WriteLine(e.Message);
}
}
Console.WriteLine("...end downloading");
没有捕获错误但没有下载文件,我尝试了几个特殊路径但似乎没有一个工作。有人能帮我吗 ?
解决方案
推荐阅读
- flutter - 带有圆边和标签文本的 TextFormField
- user-interface - 使用 vaadin-upload 组件上传文件
- angular - 重新初始化组件或强制它在 Angular 中再次运行 ngOnInit()
- python - 如何将 NetworkX 图转换为 cuGraph?
- java - glassfish mysql连接被拒绝
- php - 如何停止 WordPress 重定向到 admin.php?
- azure-devops - devops 管道 - 使用动态参数作为作业名称
- mapbox-gl - 如何将 Mapbox-GL 集成到 Power BI 自定义可视化开发中
- r - 如何使用 case_when 和 grep 一起定义一个新的变量
- javascript - 如何使用 useState 在 React 中异步设置 2 个状态