如何获取使用WebClient.DownloadFile()下载的文件路径?

时间:2013-01-24 10:14:27

标签: asp.net-mvc path webclient

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

1 个答案:

答案 0 :(得分:0)

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

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);