Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何获取使用WebClient.DownloadFile()下载的文件路径?_Asp.net Mvc_Path_Webclient - Fatal编程技术网

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

Asp.net mvc 如何获取使用WebClient.DownloadFile()下载的文件路径?,asp.net-mvc,path,webclient,Asp.net Mvc,Path,Webclient,我是网络编程新手,很抱歉提出这样的问题。我使用WebClient.DownloadFile(stringfileaddress,stringfilename)方法下载文件。我从fileaddress(即www.somelink.com/file.txt=>file.txt)获得fileName。现在,我需要得到那个文件的完整路径。如果它是桌面应用程序,不知何故我会找到它。但现在,我不知道这种情况。下载的文件应该保存在您当前的目录中。i、 例如,在 Directory.GetCurrentDire

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

下载的文件应该保存在您当前的目录中。i、 例如,在

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