首页 > 解决方案 > 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");

没有捕获错误但没有下载文件,我尝试了几个特殊路径但似乎没有一个工作。有人能帮我吗 ?

标签: c#androidxamarin

解决方案


推荐阅读