【问题标题】:How to get file path which downloaded with WebClient.DownloadFile()?如何获取使用 WebClient.DownloadFile() 下载的文件路径?
【发布时间】:2013-01-24 10:14:27
【问题描述】:

我是网络编程的新手,很抱歉这样的问题。我使用WebClient.DownloadFile(string fileAdress, string fileName) 方法下载文件。我从fileAdress 得到fileName(即www.somelink.com/file.txt => file.txt)。现在,我需要获取该文件的完整路径。如果它是桌面应用程序,我会以某种方式找到它。但是现在,我不知道情况。

【问题讨论】:

    标签: asp.net-mvc path webclient


    【解决方案1】:

    下载的文件应该保存在您的当前目录中。即,在

    Directory.GetCurrentDirectory()
    

    例子:

    using System.IO;
    using System.Net;
    
    var uri = new Uri("http://example.com/somefile.txt");
    string filename = "somefile.txt";
    
    new WebClient().DownloadFile(uri, filename);
    string filePath = Path.Combine(Directory.GetCurrentDirectory(), filename);
    

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 2021-08-04
      • 2019-01-17
      • 2014-05-29
      • 2015-11-21
      相关资源
      最近更新 更多